Refactored main.js for better readability