Fixing error in sort_graphs_by functionality