First off- break your problem down into much smaller steps. Break those small steps up into even smaller steps. Keep them separated until you have them working perfectly, then worry about combining...