remove function from loop

See http://jsperf.com/inner-closures