Refactor scripts/main.js