application states and refactoring