This improves the autogrouping algorithm to support hierarchical autogrouping. It's not guaranteed to work if we replace the reachability grouper with something more efficient, but it's good enough for now.