Refactor main.js a bit.