Implemented connected components labelling algorithm