with changed reduce function