Refactor reduce.