Refactor code, split out main.js