Fixed bug in IsSorted