Refactor graph.c