you have around 150 lines of code there.. that is... well quzah summed it up..
maybe you should try to build your program a little by little... get one *small* part working, then add somthing new. this way when you introduce a bug in the middle of writing it, you are not running all over the place trying to figure out what the problem is. you can narrow it down to what you changed last and what it affected..
get the point..
and of course pay attention to all the previous posts..