Refactored game logic into finite states.