fix  in for loop leaking into outer scope