Update main.js + refactoring