fixed checkSorted