do not create functions inside of loops as JS will create the function anew each time rather than reusing the function object