Cleanup

fixed missing semi, missing var, unused variables, storing array length to speed up for loops.