simple reduce function