Refactored gamesController.js to reduce code duplication