Moved creation of graph to a separate method.