cleanup sort and max/min