move variables to top of function