That is a ton of code. Can you break it down into something more simple and manageable that reproduces the issue?