main.js: reorganized