changed connected component function