Refactoring main.js