Added missing var scope in for loops

These missing var scopes where causing strange behaviour in large/busy applications.