Replaced forEach functions with for loops.