Refactors the js code