Move variable initialization outside of for loop