Implements quicksort