Final refactoring (formatting in main.js and entities.js)