Refactored scripts.js