refactored game code