Refactured all of main.js