Cleaning up JS code