Reorganizing the JS code.