mid: split add_variable function in two.