Replace reduce function with for loop.