moved variable declaration outside of for loop