Adding reduce function