Finished/Refactored main.js