like said above, before you start the program, list out all the no of variables that you are going to need.. then group them together as per the function that they take part in... using these groupings plan for using functions by putting these variables as local instead of global.. just make calls with functions...
if you put some time into just this planning step instead of directly coding, you will save a lot of time and confusion later on..
also, while actual coding, immediately add detailed comments about what a particular variable is doing at a particular place... that will help you code faster and concisely with clarity too...
hope i've been of some help..
regards,
wiztronix