fix IsSorted bug.