Moved loop variable declarations outside of the loop