refactor Gruntfile

I DRYed the Gruntfile a bit and also fixed a jshint warning regarding creating functions within the loop