mehdi's fix to isSorted