JSHint 1: no for global variables
JSHint 2: Don't make functions within a loop
JSHint 3: misc fixes