Clean up, refactor, and comment some JavaScript.