Implemented connected component grouping.