Refactors graph creation