modified qsort