Refactored script.js