add isSorted function