Cleaning up the JS code