simpler keep_variable function