Completed the first round of JavaScript refactoring. It all seems to work well enough now.