Slight efficiency improvement with JSHint

I used [JSHint](http://jshint.com/) to look for potential trouble spots. Only one was found: a loop was creating the same function over and over, so I moved it up just before the loop.