Fix non-flattened index calculation.