Small refactors in scripts.js.