Implements quick sort