refactoring of the quick sort