Move variable declaration to the top of the function