fix bugs in quick selection algorithm