Major refactoring: making heavy use of State design pattern to handle complexity