Cleaned up some of gen_graph, still need to optimize