Refactors the javascript code for readability