declare var outside of loop
Merge pull request #2377 from webzwo0i/avoid-global-vairables

declare var outside of loop