Cleaning up code

removing unnecessary whitespace, globalizing vars some so the loops
don't needlessly iterate through code, reworked some for loop variables
into the for loop declaration.