Move variable declaration to proper scope