update the logic of connect_nodes