Improve grounding algorithm, removing redundancies.