Refactor game code