avoid function calls in for loop