Refactoring.
Moved variable declaration to foreach