Move variable declaration to the start of the function