Refactor main.js.