Refactors the JavaScript