Moving variable inside function