Refactoring, working with states