refactor main.js