Reducer refactoring and bug fix.