added quick sort optimization