fix most "Don't make functions within a loop" jshint errors