fix loop index