slightly reduct overhead of function creation

by passing a function into the loop through closure