refactored game logic to make more concise and readable