fix and refactor reduce