improve connectivity algo