Fix loop index