mid variable changed from global to local