Refactor main.js into several js modules.
Application behavior should be unchanged.