Move variable declaration out of the loop