main.js refactoring