added improved qsort