Move variable declaration closer to where it's needed