refactor quick sort while loop