refactored selection index calculation logic