refactoring main.js