Refactoring of game.js