Fix variable access within for loops