reduce function simplified