Refactor main.js to only use generally useful code