Finish refactoring of JavaScript