Refactor reducer code