If you suspect that you are running out of memory, you are probably right. Meanwhile, though, you are wasting our time by not posting ALL of your code.
I, for one, won't even read any of it knowing that it isn't complete. Where you think the problem is may not be where it is at all.