Incidentally, you really should reduce the code needed to demonstrate your problem to the bare minimum. You posted too much code, and I don't have the patience to read it.
In that case, rather than complaining, we could teach the OP about <readmore> tags.
When posting long messages - particularly those containing large chunks of code - it's often wise to enclose the 'long part' like this:
<readmore> # long part </readmore>
That way, a link is automatically created so we only have to see the enclosed text if we need to. This keeps the visible post much shorter and easier to digest. This and other useful info is available at Writeup Formatting Tips.
Hope that helps!
Update: Changed node title to better reflect content.
Update 2: Changed node title again to 'link' to original thread.