Removing function definitions from inside loops