Refactoring for quicksort