Refactored out the graph code.