Refactoring to apply a redux-like pattern.