move variables closer to the functions that use them