Eh, that's a huge sourcecode to search for a bug.
I'd suggest to do the following:
Systematicly isolate the bug. One simple solution is to add an end command to a line that you know was still executed before freezing. Then move the end command forward, one by one. Soon you'll realize where it's freezing. That's already half of the work - or more.
I'd suggest to do the following:
Systematicly isolate the bug. One simple solution is to add an end command to a line that you know was still executed before freezing. Then move the end command forward, one by one. Soon you'll realize where it's freezing. That's already half of the work - or more.