fix global leak of loop variable `i`