Adding missing `var` keyword

It was removed in the latest PR by me (>.>), which reintroduced the bug we had before using `foreach`.