refactoring into state