refactor scripts.js