optimize quick sort code