Refactored main.js