Refactor Conneted component labeling