replace index variable name to avoid shadowed global declarations