moved graph code into graph file, and cleaned it up