Refactor main.js