cleaned gravity code