ranking logic optimized