Fix bugs in graph code