moving var to beginning of function