Quickselect function moved to a helper.