simplify the connected components code