Added reduce function