Revised the reduce function to something that looked more like fold.