Fixed max index calculation.