Found bug, minmax should have been minmax_element.