Finished reduce function