refactor into different states