Refactor the main.js file to a view and a controller