added reduce function