improve index calculation