optimized quicksort