diff --git a/matlab/dynare.m b/matlab/dynare.m
index 6c9ba4fee123111d3704d2c7099181d28842e8c1..65be458847206bf2ff0edc7181c47a82906fb914 100644
--- a/matlab/dynare.m
+++ b/matlab/dynare.m
@@ -281,10 +281,10 @@ try
     evalin('base',[fname '.driver']) ;
 catch ME
     W = evalin('base','whos');
-    diary off   
-    if ismember(fname,[W(:).name])
+    diary off
+    if ismember(fname,{W(:).name})
         error('Your base workspace already contains a variable with the same name as the mod-file. You need to delete it or rename the mod-file.')        
-    else        
+    else
         rethrow(ME)    
     end    
 end
diff --git a/matlab/simult_.m b/matlab/simult_.m
index 508af26e435fe890db154dd1a1f9733c29b46911..1ab1729cfebcc9780e6c2dde88ec6f36a431a4a6 100644
--- a/matlab/simult_.m
+++ b/matlab/simult_.m
@@ -42,7 +42,8 @@ y_ = zeros(size(y0,1),iter+M_.maximum_lag);
 y_(:,1) = y0;
 
 if options_.loglinear && ~options_.logged_steady_state
-    dr.ys=log(dr.ys);
+    k = get_all_variables_but_lagged_leaded_exogenous(M_);
+    dr.ys(k)=log(dr.ys(k));
 end
 
 if ~options_.k_order_solver || (options_.k_order_solver && options_.pruning) %if k_order_pert is not used or if we do not use Dynare++ with k_order_pert
diff --git a/matlab/store_smoother_results.m b/matlab/store_smoother_results.m
index 645289445fce399b3243e589b34041148e0ae0cb..b53283412888242bdead1eb75d649d068bd2c433 100644
--- a/matlab/store_smoother_results.m
+++ b/matlab/store_smoother_results.m
@@ -79,6 +79,12 @@ end
 
 if options_.loglinear
     oo_.Smoother.loglinear = true;
+    if ~isempty(M_.aux_vars) % deal with lead/lag of exogenous variables
+        exo_lead_lag_index = M_.orig_endo_nbr + find(([M_.aux_vars.type] == 2) | ([M_.aux_vars.type]  == 3));
+    else
+        exo_lead_lag_index =[];
+    end
+
 else
     oo_.Smoother.loglinear = false;
 end
@@ -137,6 +143,9 @@ if ~isempty(options_.nk) && options_.nk ~= 0
     i_endo_declaration_order = oo_.dr.order_var(i_endo_in_dr_matrices); %get indices of smoothed variables in name vector
     if  options_.loglinear %logged steady state must be used
         constant_all_variables=repmat(log(ys(i_endo_declaration_order))',[length(options_.filter_step_ahead),1,gend+max(options_.filter_step_ahead)]);
+        if ~isempty(exo_lead_lag_index) && any(ismember(i_endo_declaration_order,exo_lead_lag_index)) % deal with lead/lag of exogenous variables
+            constant_all_variables(:,ismember(i_endo_declaration_order,exo_lead_lag_index),:)=repmat(ys(i_endo_declaration_order(ismember(i_endo_declaration_order,exo_lead_lag_index)))',[length(options_.filter_step_ahead),1,gend+max(options_.filter_step_ahead)]);
+        end
     elseif ~options_.loglinear %unlogged steady state must be used
         constant_all_variables=repmat((ys(i_endo_declaration_order))',[length(options_.filter_step_ahead),1,gend+max(options_.filter_step_ahead)]);
     end
@@ -157,7 +166,11 @@ for i_endo_in_bayestopt_smoother_varlist=bayestopt_.smoother_saved_var_list'
     i_endo_declaration_order = oo_.dr.order_var(i_endo_in_dr); %get indices of smoothed variables in name vector
     %% Compute constant
     if  options_.loglinear == 1 %logged steady state must be used
-        constant_current_variable=repmat(log(ys(i_endo_declaration_order)),gend,1);
+        if ~isempty(exo_lead_lag_index) && ismember(i_endo_declaration_order,exo_lead_lag_index)% deal with lead/lag of exogenous variables
+            constant_current_variable=repmat(ys(i_endo_declaration_order),gend,1);
+        else
+            constant_current_variable=repmat(log(ys(i_endo_declaration_order)),gend,1);
+        end
     elseif options_.loglinear == 0 %unlogged steady state must be used
         constant_current_variable=repmat((ys(i_endo_declaration_order)),gend,1);
     end