consolidate quicksort code