Refactors game logic.