corrected index counting