HTML/JavaScript refactor