Fixed print_graph function (removed side effects)