Begin refactoring main.js