Refactoring to states