change sort_max to rely on find_max_index