started refactoring main.js