Refactor the graph printing into its own function.