fix possible bug when connecting a nonexisting node in a graph