refactored code in game.rb