fixed calculation of current row index