avoid functions in for loop

undefined code removed