separate connected components code into a header file