Fix to variable scope