Performance improvements to ToVector and RegionGroup