optimized index calculation