Check if the graph contains the node before calling remove() to eliminate an error throw