WIP: Refactoring the graph code