error resolved: made mid global to local variable