Refactors the JS code