add reduce function