optimized selection algorithm