move variable declaration to beginning of function