moved loop variable declaration out of for()