Stop declaring your variables at the beginning of your functions... it is confusing as hell.