corrected connexity detection function