Some main.js refactoring