Refactoring game logic and tests