Adding check for connectedness