Refactoring the javascript.