I posted the code I have on my initial post. If you're looking at it and see something you don't understand let me know. Otherwise I don't care too much about conventions and stuff. I'll worry about making some subroutines and stuff like that after I get everything working. But it seems to freeze or something and I can't figure out why...
I'm very wary of even looking at code that's not strict-safe (especially code that long), and lots of the code you posted is not relevant to your problem.
Start a new thread for the new problem, and do a proper job of asking the question. Specifically, I'm interested in minimal, runnable code, which might require that you provide some data.