diff --git a/matlab/estimation/dynare_estimation_init.m b/matlab/estimation/dynare_estimation_init.m
index f025548f5b6468ab5d8cc4c5e31e15dfde22dbb5..fe246cbc26c4bf4e9e51a47d6032a2153e1325e9 100644
--- a/matlab/estimation/dynare_estimation_init.m
+++ b/matlab/estimation/dynare_estimation_init.m
@@ -149,7 +149,7 @@ if ~isempty(bayestopt_) && any(bayestopt_.pshape==0) && any(bayestopt_.pshape~=0
     error('Estimation must be either fully ML or fully Bayesian. Maybe you forgot to specify a prior distribution.')
 end
 % Check if a _prior_restrictions.m file exists
-if exist([M_.fname '_prior_restrictions.m'])
+if exist([M_.fname '_prior_restrictions.m'],'file')
     options_.prior_restrictions.status = 1;
     options_.prior_restrictions.routine = str2func([M_.fname '_prior_restrictions']);
 end
diff --git a/matlab/kalman/DsgeSmoother.m b/matlab/kalman/DsgeSmoother.m
index c84b800286e301ff5a65c02db894c4c4c5f723e9..7a9ecd279a9bc0714c53f34a76daf981e491e8ea 100644
--- a/matlab/kalman/DsgeSmoother.m
+++ b/matlab/kalman/DsgeSmoother.m
@@ -215,12 +215,8 @@ elseif options_.lik_init == 4           % Start from the solution of the Riccati
 elseif options_.lik_init == 5            % Old diffuse Kalman filter only for the non stationary variables
     [eigenvect, eigenv] = eig(T);
     eigenv = diag(eigenv);
-    nstable = length(find(abs(abs(eigenv)-1) > 1e-7));
-    unstable = find(abs(abs(eigenv)-1) < 1e-7);
-    V = eigenvect(:,unstable);
-    indx_unstable = find(sum(abs(V),2)>1e-5);
+    V = eigenvect(:,abs(abs(eigenv)-1) < 1e-7);
     stable = find(sum(abs(V),2)<1e-5);
-    nunit = length(eigenv) - nstable;
     Pstar = options_.Harvey_scale_factor*eye(np);
     if kalman_algo ~= 2
         kalman_algo = 1;
@@ -233,7 +229,6 @@ elseif options_.lik_init == 5            % Old diffuse Kalman filter only for th
 end
 kalman_tol = options_.kalman_tol;
 diffuse_kalman_tol = options_.diffuse_kalman_tol;
-riccati_tol = options_.riccati_tol;
 data1 = Y-trend;
 % -----------------------------------------------------------------------------
 %  4. Kalman smoother
diff --git a/matlab/kalman/evaluate_smoother.m b/matlab/kalman/evaluate_smoother.m
index f093701df8e428693db326b38b37710e69bc5026..599bc5b96de928021f2cb6059390504892241905 100644
--- a/matlab/kalman/evaluate_smoother.m
+++ b/matlab/kalman/evaluate_smoother.m
@@ -39,7 +39,7 @@ function [oo_,M_,options_,bayestopt_,Smoothed_variables_declaration_order_deviat
 % [1] This function use persistent variables for the dataset and the description of the missing observations. Consequently, if this function
 %     is called more than once (by changing the value of parameters) the sample *must not* change.
 
-% Copyright © 2010-2023 Dynare Team
+% Copyright © 2010-2024 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -127,13 +127,13 @@ else
 end
 if ~(options_.occbin.smoother.status && options_.occbin.smoother.inversion_filter)
     if ~options_.occbin.smoother.status || (options_.occbin.smoother.status && oo_.occbin.smoother.error_flag==0)
-        [oo_]=store_smoother_results(M_,oo_,options_,bayestopt_,dataset_,dataset_info,atT,innov,measurement_error,updated_variables,ys,trend_coeff,aK,P,PK,decomp,Trend,state_uncertainty);
+        [oo_,yf]=store_smoother_results(M_,oo_,options_,bayestopt_,dataset_,dataset_info,atT,innov,measurement_error,updated_variables,ys,trend_coeff,aK,P,PK,decomp,Trend,state_uncertainty);
     end
 else
     if ~oo_.occbin.smoother.error_flag
         options_nk=options_.nk;
         options_.nk=[]; %unset options_.nk and reset it later
-        [oo_]=store_smoother_results(M_,oo_,options_,bayestopt_,dataset_,dataset_info,atT,innov,measurement_error,updated_variables,ys,trend_coeff);
+        [oo_,yf]=store_smoother_results(M_,oo_,options_,bayestopt_,dataset_,dataset_info,atT,innov,measurement_error,updated_variables,ys,trend_coeff);
         options_.nk=options_nk;
     else
         fprintf('\nIVF: smoother did not succeed. No results will be written to oo_.\n')
@@ -143,6 +143,10 @@ if nargout>4
     Smoothed_variables_declaration_order_deviation_form=atT(oo_.dr.inv_order_var(bayestopt_.smoother_var_list),:);
 end
 
+if ~options_.occbin.smoother.status || (options_.occbin.smoother.status && oo_.occbin.smoother.error_flag==0)
+    plot_classical_smoother_results(M_,oo_,options_,dataset_info,dataset_,estim_params_,yf)
+end
+
 %reset qz_criterium
 options_.qz_criterium=qz_criterium_old;
 oo_.gui.ran_calib_smoother = true;
diff --git a/matlab/kalman/plot_classical_smoother_results.m b/matlab/kalman/plot_classical_smoother_results.m
new file mode 100644
index 0000000000000000000000000000000000000000..578d3166a146a40cbff6e9b57dde54fbeb61575c
--- /dev/null
+++ b/matlab/kalman/plot_classical_smoother_results.m
@@ -0,0 +1,219 @@
+function plot_classical_smoother_results(M_,oo_,options_,dataset_info,dataset_,estim_params_,yf)
+% function plot_classical_smoother_results(M_,oo_,options_,dataset_info,dataset_,estim_params_,yf)
+% Inputs:
+%   M_              [structure]     storing the model information
+%   oo_             [structure]     storing the results
+%   options_        [structure]     storing the options
+%   dataset_        [structure]     storing the dataset
+%   estim_params_   [structure]     storing information about estimated parameters
+%   yf              [double]        (nvarobs*T) matrix storing the smoothed observed variables (order of options_.varobs)
+%
+% Outputs:
+%   None
+
+% Copyright © 2024 Dynare Team
+%
+% This file is part of Dynare.
+%
+% Dynare is free software: you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation, either version 3 of the License, or
+% (at your option) any later version.
+%
+% Dynare is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+% GNU General Public License for more details.
+%
+% You should have received a copy of the GNU General Public License
+% along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
+
+gend= dataset_.nobs;
+n_varobs = length(options_.varobs);
+
+if ~options_.nograph
+    [nbplt,nr,nc,~,~,nstar] = pltorg(M_.exo_nbr);
+    if ~exist([M_.dname '/graphs'],'dir')
+        mkdir(M_.dname,'graphs');
+    end
+    if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
+        fidTeX = fopen([M_.dname, '/graphs/' M_.fname '_SmoothedShocks.tex'],'w');
+        fprintf(fidTeX,'%% TeX eps-loader file generated by dynare_estimation_1.m (Dynare).\n');
+        fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
+        fprintf(fidTeX,' \n');
+    end
+    for plt = 1:nbplt
+        fh = dyn_figure(options_.nodisplay,'Name','Smoothed shocks');
+        nstar0=min(nstar,M_.exo_nbr-(plt-1)*nstar);
+        if gend==1
+            marker_string{1,1}='-ro';
+            marker_string{2,1}='-ko';
+        else
+            marker_string{1,1}='-r';
+            marker_string{2,1}='-k';
+        end
+        for i=1:nstar0
+            k = (plt-1)*nstar+i;
+            subplot(nr,nc,i);
+            plot([1 gend],[0 0],marker_string{1,1},'linewidth',.5)
+            hold on
+            plot(1:gend,oo_.SmoothedShocks.(M_.exo_names{k}),marker_string{2,1},'linewidth',1)
+            hold off
+            name = M_.exo_names{k};
+            if ~isempty(options_.XTick)
+                set(gca,'XTick',options_.XTick)
+                set(gca,'XTickLabel',options_.XTickLabel)
+            end
+            if gend>1
+                xlim([1 gend])
+            end
+            if options_.TeX
+                title(['$' M_.exo_names_tex{k} '$'],'Interpreter','latex')
+            else
+                title(name,'Interpreter','none')
+            end
+        end
+        dyn_saveas(fh,[M_.dname, '/graphs/' M_.fname '_SmoothedShocks' int2str(plt)],options_.nodisplay,options_.graph_format);
+        if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
+            fprintf(fidTeX,'\\begin{figure}[H]\n');
+            fprintf(fidTeX,'\\centering \n');
+            fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s_SmoothedShocks%s}\n',options_.figures.textwidth*min(i/nc,1),[M_.dname, '/graphs/' M_.fname],int2str(plt));
+            fprintf(fidTeX,'\\caption{Smoothed shocks.}');
+            fprintf(fidTeX,'\\label{Fig:SmoothedShocks:%s}\n',int2str(plt));
+            fprintf(fidTeX,'\\end{figure}\n');
+            fprintf(fidTeX,'\n');
+        end
+    end
+    if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
+        fprintf(fidTeX,'\n');
+        fprintf(fidTeX,'%% End of TeX file.\n');
+        fclose(fidTeX);
+    end
+end
+if estim_params_.nvn
+    number_of_plots_to_draw = 0;
+    index = [];
+    for obs_iter=1:n_varobs
+        if max(abs(oo_.SmoothedMeasurementErrors.(options_.varobs{obs_iter}))) > options_.ME_plot_tol
+            number_of_plots_to_draw = number_of_plots_to_draw + 1;
+            index = cat(1,index,obs_iter);
+        end
+    end
+    if ~options_.nograph
+        [nbplt,nr,nc,~,~,nstar] = pltorg(number_of_plots_to_draw);
+        if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
+            fidTeX = fopen([M_.dname, '/graphs/' M_.fname '_SmoothedObservationErrors.tex'],'w');
+            fprintf(fidTeX,'%% TeX eps-loader file generated by dynare_estimation_1.m (Dynare).\n');
+            fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
+            fprintf(fidTeX,' \n');
+        end
+        for plt = 1:nbplt
+            fh = dyn_figure(options_.nodisplay,'Name','Smoothed observation errors');
+            nstar0=min(nstar,number_of_plots_to_draw-(plt-1)*nstar);
+            if gend==1
+                marker_string{1,1}='-ro';
+                marker_string{2,1}='-ko';
+            else
+                marker_string{1,1}='-r';
+                marker_string{2,1}='-k';
+            end
+            for i=1:nstar0
+                k = (plt-1)*nstar+i;
+                subplot(nr,nc,i);
+                name = options_.varobs{index(k)};
+                plot([1 gend],[0 0],marker_string{1,1},'linewidth',.5)
+                hold on
+                plot(1:gend,oo_.SmoothedMeasurementErrors.(name),marker_string{2,1},'linewidth',1)
+                hold off
+                if gend>1
+                    xlim([1 gend])
+                end
+                if ~isempty(options_.XTick)
+                    set(gca,'XTick',options_.XTick)
+                    set(gca,'XTickLabel',options_.XTickLabel)
+                end
+                if options_.TeX
+                    idx = strmatch(options_.varobs{index(k)}, M_.endo_names, 'exact');
+                    title(['$' M_.endo_names_tex{idx} '$'],'Interpreter','latex')
+                else
+                    title(name,'Interpreter','none')
+                end
+            end
+            dyn_saveas(fh,[M_.dname, '/graphs/' M_.fname '_SmoothedObservationErrors' int2str(plt)],options_.nodisplay,options_.graph_format);
+            if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
+                fprintf(fidTeX,'\\begin{figure}[H]\n');
+                fprintf(fidTeX,'\\centering \n');
+                fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s_SmoothedObservationErrors%s}\n',options_.figures.textwidth*min(i/nc,1),[M_.dname, '/graphs/' M_.fname],int2str(plt));
+                fprintf(fidTeX,'\\caption{Smoothed observation errors.}');
+                fprintf(fidTeX,'\\label{Fig:SmoothedObservationErrors:%s}\n',int2str(plt));
+                fprintf(fidTeX,'\\end{figure}\n');
+                fprintf(fidTeX,'\n');
+            end
+        end
+        if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
+            fprintf(fidTeX,'\n');
+            fprintf(fidTeX,'%% End of TeX file.\n');
+            fclose(fidTeX);
+        end
+    end
+end
+%%
+%%  Historical and smoothed variabes
+%%
+if ~options_.nograph
+    [nbplt,nr,nc,~,~,nstar] = pltorg(n_varobs);
+    if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
+        fidTeX = fopen([M_.dname, '/graphs/' M_.fname '_HistoricalAndSmoothedVariables.tex'],'w');
+        fprintf(fidTeX,'%% TeX eps-loader file generated by dynare_estimation_1.m (Dynare).\n');
+        fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
+        fprintf(fidTeX,' \n');
+    end
+    for plt = 1:nbplt
+        fh = dyn_figure(options_.nodisplay,'Name','Historical and smoothed variables');
+        nstar0=min(nstar,n_varobs-(plt-1)*nstar);
+        if gend==1
+            marker_string{1,1}='-ro';
+            marker_string{2,1}='--ko';
+        else
+            marker_string{1,1}='-r';
+            marker_string{2,1}='--k';
+        end
+        for i=1:nstar0
+            k = (plt-1)*nstar+i;
+            subplot(nr,nc,i);
+            name = options_.varobs{k};
+            plot(1:gend,yf(k,:),marker_string{1,1},'linewidth',1)
+            hold on
+            plot(1:gend,dataset_info.rawdata(:,k),marker_string{2,1},'linewidth',1)
+            hold off
+            if ~isempty(options_.XTick)
+                set(gca,'XTick',options_.XTick)
+                set(gca,'XTickLabel',options_.XTickLabel)
+            end
+            if gend>1
+                xlim([1 gend])
+            end
+            if options_.TeX
+                idx = strmatch(options_.varobs{k}, M_.endo_names,'exact');
+                title(['$' M_.endo_names_tex{idx} '$'],'Interpreter','latex')
+            else
+                title(name,'Interpreter','none')
+            end
+        end
+        dyn_saveas(fh,[M_.dname, '/graphs/' M_.fname '_HistoricalAndSmoothedVariables' int2str(plt)],options_.nodisplay,options_.graph_format);
+        if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
+            fprintf(fidTeX,'\\begin{figure}[H]\n');
+            fprintf(fidTeX,'\\centering \n');
+            fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s_HistoricalAndSmoothedVariables%s}\n',options_.figures.textwidth*min(i/nc,1),[M_.dname, '/graphs/' M_.fname],int2str(plt));
+            fprintf(fidTeX,'\\caption{Historical and smoothed variables.}');
+            fprintf(fidTeX,'\\label{Fig:HistoricalAndSmoothedVariables:%s}\n',int2str(plt));
+            fprintf(fidTeX,'\\end{figure}\n');
+            fprintf(fidTeX,'\n');
+        end
+    end
+    if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
+        fprintf(fidTeX,'\n');
+        fprintf(fidTeX,'%% End of TeX file.\n');
+        fclose(fidTeX);
+    end
+end
diff --git a/matlab/kalman/save_display_classical_smoother_results.m b/matlab/kalman/save_display_classical_smoother_results.m
index f7f2f981e710722c51b9f8ff466d92773f743cac..46d42c99694af366a4b6df4cc0602eba134ec0ba 100644
--- a/matlab/kalman/save_display_classical_smoother_results.m
+++ b/matlab/kalman/save_display_classical_smoother_results.m
@@ -30,15 +30,12 @@ function oo_=save_display_classical_smoother_results(xparam1,M_,oo_,options_,bay
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
 
-
-gend= dataset_.nobs;
-% Set the number of observed variables.
-n_varobs = length(options_.varobs);
-
+smoother_error=false;
 if options_.occbin.smoother.status && options_.occbin.smoother.inversion_filter
     [~, info, ~, ~, ~, ~, ~, ~, ~, ~, oo_.dr, atT, innov, oo_.occbin.smoother.regime_history] = occbin.IVF_posterior(xparam1,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,prior_bounds(bayestopt_,options_.prior_trunc),oo_.dr, oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
     if ismember(info(1),[303,304,306])
         fprintf('\nIVF: smoother did not succeed. No results will be written to oo_.\n')
+        smoother_error=true;
     else
         updated_variables = atT*nan;
         measurement_error=[];
@@ -54,199 +51,16 @@ else
     if options_.occbin.smoother.status
         [atT,innov,measurement_error,updated_variables,ys,trend_coeff,aK,~,~,P,PK,decomp,Trend,state_uncertainty,oo_,bayestopt_] = occbin.DSGE_smoother(xparam1,dataset_.nobs,transpose(dataset_.data),dataset_info.missing.aindex,dataset_info.missing.state,M_,oo_,options_,bayestopt_,estim_params_,dataset_,dataset_info);
         if oo_.occbin.smoother.error_flag(1)==0
-            oo_ = store_smoother_results(M_,oo_,options_,bayestopt_,dataset_,dataset_info,atT,innov,measurement_error,updated_variables,ys,trend_coeff,aK,P,PK,decomp,Trend,state_uncertainty);
+            [oo_, yf] = store_smoother_results(M_,oo_,options_,bayestopt_,dataset_,dataset_info,atT,innov,measurement_error,updated_variables,ys,trend_coeff,aK,P,PK,decomp,Trend,state_uncertainty);
         else
+            smoother_error=true;
             fprintf('\nOccbin: smoother did not succeed. No results will be written to oo_.\n')
         end
     else
         [atT,innov,measurement_error,updated_variables,ys,trend_coeff,aK,~,~,P,PK,decomp,Trend,state_uncertainty,oo_,bayestopt_] = DsgeSmoother(xparam1,dataset_.nobs,transpose(dataset_.data),dataset_info.missing.aindex,dataset_info.missing.state,M_,oo_,options_,bayestopt_,estim_params_);
-        oo_ = store_smoother_results(M_,oo_,options_,bayestopt_,dataset_,dataset_info,atT,innov,measurement_error,updated_variables,ys,trend_coeff,aK,P,PK,decomp,Trend,state_uncertainty);
-    end
-    [oo_,yf]=store_smoother_results(M_,oo_,options_,bayestopt_,dataset_,dataset_info,atT,innov,measurement_error,updated_variables,ys,trend_coeff,aK,P,PK,decomp,Trend,state_uncertainty);
-end
-if ~options_.nograph
-    [nbplt,nr,nc,~,~,nstar] = pltorg(M_.exo_nbr);
-    if ~exist([M_.dname '/graphs'],'dir')
-        mkdir(M_.dname,'graphs');
-    end
-    if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
-        fidTeX = fopen([M_.dname, '/graphs/' M_.fname '_SmoothedShocks.tex'],'w');
-        fprintf(fidTeX,'%% TeX eps-loader file generated by dynare_estimation_1.m (Dynare).\n');
-        fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
-        fprintf(fidTeX,' \n');
-    end
-    for plt = 1:nbplt
-        fh = dyn_figure(options_.nodisplay,'Name','Smoothed shocks');
-        nstar0=min(nstar,M_.exo_nbr-(plt-1)*nstar);
-        if gend==1
-            marker_string{1,1}='-ro';
-            marker_string{2,1}='-ko';
-        else
-            marker_string{1,1}='-r';
-            marker_string{2,1}='-k';
-        end
-        for i=1:nstar0
-            k = (plt-1)*nstar+i;
-            subplot(nr,nc,i);
-            plot([1 gend],[0 0],marker_string{1,1},'linewidth',.5)
-            hold on
-            plot(1:gend,innov(k,:),marker_string{2,1},'linewidth',1)
-            hold off
-            name = M_.exo_names{k};
-            if ~isempty(options_.XTick)
-                set(gca,'XTick',options_.XTick)
-                set(gca,'XTickLabel',options_.XTickLabel)
-            end
-            if gend>1
-                xlim([1 gend])
-            end
-            if options_.TeX
-                title(['$' M_.exo_names_tex{k} '$'],'Interpreter','latex')
-            else
-                title(name,'Interpreter','none')
-            end
-        end
-        dyn_saveas(fh,[M_.dname, '/graphs/' M_.fname '_SmoothedShocks' int2str(plt)],options_.nodisplay,options_.graph_format);
-        if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
-            fprintf(fidTeX,'\\begin{figure}[H]\n');
-            fprintf(fidTeX,'\\centering \n');
-            fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s_SmoothedShocks%s}\n',options_.figures.textwidth*min(i/nc,1),[M_.dname, '/graphs/' M_.fname],int2str(plt));
-            fprintf(fidTeX,'\\caption{Smoothed shocks.}');
-            fprintf(fidTeX,'\\label{Fig:SmoothedShocks:%s}\n',int2str(plt));
-            fprintf(fidTeX,'\\end{figure}\n');
-            fprintf(fidTeX,'\n');
-        end
-    end
-    if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
-        fprintf(fidTeX,'\n');
-        fprintf(fidTeX,'%% End of TeX file.\n');
-        fclose(fidTeX);
-    end
-end
-if estim_params_.nvn
-    number_of_plots_to_draw = 0;
-    index = [];
-    for obs_iter=1:n_varobs
-        if max(abs(measurement_error(obs_iter,:))) > options_.ME_plot_tol
-            number_of_plots_to_draw = number_of_plots_to_draw + 1;
-            index = cat(1,index,obs_iter);
-        end
-    end
-    if ~options_.nograph
-        [nbplt,nr,nc,~,~,nstar] = pltorg(number_of_plots_to_draw);
-        if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
-            fidTeX = fopen([M_.dname, '/graphs/' M_.fname '_SmoothedObservationErrors.tex'],'w');
-            fprintf(fidTeX,'%% TeX eps-loader file generated by dynare_estimation_1.m (Dynare).\n');
-            fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
-            fprintf(fidTeX,' \n');
-        end
-        for plt = 1:nbplt
-            fh = dyn_figure(options_.nodisplay,'Name','Smoothed observation errors');
-            nstar0=min(nstar,number_of_plots_to_draw-(plt-1)*nstar);
-            if gend==1
-                marker_string{1,1}='-ro';
-                marker_string{2,1}='-ko';
-            else
-                marker_string{1,1}='-r';
-                marker_string{2,1}='-k';
-            end
-            for i=1:nstar0
-                k = (plt-1)*nstar+i;
-                subplot(nr,nc,i);
-                plot([1 gend],[0 0],marker_string{1,1},'linewidth',.5)
-                hold on
-                plot(1:gend,measurement_error(index(k),:),marker_string{2,1},'linewidth',1)
-                hold off
-                name = options_.varobs{index(k)};
-                if gend>1
-                    xlim([1 gend])
-                end
-                if ~isempty(options_.XTick)
-                    set(gca,'XTick',options_.XTick)
-                    set(gca,'XTickLabel',options_.XTickLabel)
-                end
-                if options_.TeX
-                    idx = strmatch(options_.varobs{index(k)}, M_.endo_names, 'exact');
-                    title(['$' M_.endo_names_tex{idx} '$'],'Interpreter','latex')
-                else
-                    title(name,'Interpreter','none')
-                end
-            end
-            dyn_saveas(fh,[M_.dname, '/graphs/' M_.fname '_SmoothedObservationErrors' int2str(plt)],options_.nodisplay,options_.graph_format);
-            if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
-                fprintf(fidTeX,'\\begin{figure}[H]\n');
-                fprintf(fidTeX,'\\centering \n');
-                fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s_SmoothedObservationErrors%s}\n',options_.figures.textwidth*min(i/nc,1),[M_.dname, '/graphs/' M_.fname],int2str(plt));
-                fprintf(fidTeX,'\\caption{Smoothed observation errors.}');
-                fprintf(fidTeX,'\\label{Fig:SmoothedObservationErrors:%s}\n',int2str(plt));
-                fprintf(fidTeX,'\\end{figure}\n');
-                fprintf(fidTeX,'\n');
-            end
-        end
-        if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
-            fprintf(fidTeX,'\n');
-            fprintf(fidTeX,'%% End of TeX file.\n');
-            fclose(fidTeX);
-        end
-    end
-end
-%%
-%%  Historical and smoothed variabes
-%%
-if ~options_.nograph
-    [nbplt,nr,nc,~,~,nstar] = pltorg(n_varobs);
-    if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
-        fidTeX = fopen([M_.dname, '/graphs/' M_.fname '_HistoricalAndSmoothedVariables.tex'],'w');
-        fprintf(fidTeX,'%% TeX eps-loader file generated by dynare_estimation_1.m (Dynare).\n');
-        fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
-        fprintf(fidTeX,' \n');
-    end
-    for plt = 1:nbplt
-        fh = dyn_figure(options_.nodisplay,'Name','Historical and smoothed variables');
-        nstar0=min(nstar,n_varobs-(plt-1)*nstar);
-        if gend==1
-            marker_string{1,1}='-ro';
-            marker_string{2,1}='--ko';
-        else
-            marker_string{1,1}='-r';
-            marker_string{2,1}='--k';
-        end
-        for i=1:nstar0
-            k = (plt-1)*nstar+i;
-            subplot(nr,nc,i);
-            plot(1:gend,yf(k,:),marker_string{1,1},'linewidth',1)
-            hold on
-            plot(1:gend,dataset_info.rawdata(:,k),marker_string{2,1},'linewidth',1)
-            hold off
-            name = options_.varobs{k};
-            if ~isempty(options_.XTick)
-                set(gca,'XTick',options_.XTick)
-                set(gca,'XTickLabel',options_.XTickLabel)
-            end
-            if gend>1
-                xlim([1 gend])
-            end
-            if options_.TeX
-                idx = strmatch(options_.varobs{k}, M_.endo_names,'exact');
-                title(['$' M_.endo_names_tex{idx} '$'],'Interpreter','latex')
-            else
-                title(name,'Interpreter','none')
-            end
-        end
-        dyn_saveas(fh,[M_.dname, '/graphs/' M_.fname '_HistoricalAndSmoothedVariables' int2str(plt)],options_.nodisplay,options_.graph_format);
-        if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
-            fprintf(fidTeX,'\\begin{figure}[H]\n');
-            fprintf(fidTeX,'\\centering \n');
-            fprintf(fidTeX,'\\includegraphics[width=%2.2f\\textwidth]{%s_HistoricalAndSmoothedVariables%s}\n',options_.figures.textwidth*min(i/nc,1),[M_.dname, '/graphs/' M_.fname],int2str(plt));
-            fprintf(fidTeX,'\\caption{Historical and smoothed variables.}');
-            fprintf(fidTeX,'\\label{Fig:HistoricalAndSmoothedVariables:%s}\n',int2str(plt));
-            fprintf(fidTeX,'\\end{figure}\n');
-            fprintf(fidTeX,'\n');
-        end
-    end
-    if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
-        fprintf(fidTeX,'\n');
-        fprintf(fidTeX,'%% End of TeX file.\n');
-        fclose(fidTeX);
+        [oo_,yf]=store_smoother_results(M_,oo_,options_,bayestopt_,dataset_,dataset_info,atT,innov,measurement_error,updated_variables,ys,trend_coeff,aK,P,PK,decomp,Trend,state_uncertainty);
     end
 end
+if ~smoother_error
+    plot_classical_smoother_results(M_,oo_,options_,dataset_info,dataset_,estim_params_,yf);
+end
\ No newline at end of file