Fix jshint problems

Move function definition outside of for loop