added connected components handling