Refactored game logic