move variables to function