refactored main.js of game