Refactor quicksort