redefine reduce function