refactor of game.js and related files