diff --git a/matlab/check_posterior_sampler_options.m b/matlab/check_posterior_sampler_options.m
index 2f7a80b828786cab847b383f73e961b998323ef3..3d854869352f393f58fd411e74a2dbf2c20018d5 100644
--- a/matlab/check_posterior_sampler_options.m
+++ b/matlab/check_posterior_sampler_options.m
@@ -1,19 +1,23 @@
-function [posterior_sampler_options, options_] = check_posterior_sampler_options(posterior_sampler_options, options_, bounds)
+function [posterior_sampler_options, options_, bayestopt_] = check_posterior_sampler_options(posterior_sampler_options, options_, bounds, bayestopt_)
 
-% function [posterior_sampler_options, options_] = check_posterior_sampler_options(posterior_sampler_options, options_, bounds)
+% function [posterior_sampler_options, options_, bayestopt_] = check_posterior_sampler_options(posterior_sampler_options, options_, bounds, bayestopt_)
 % initialization of posterior samplers
 %
 % INPUTS
 %   posterior_sampler_options:       posterior sampler options
 %   options_:       structure storing the options
+%   bounds:         structure containing prior bounds
+%   bayestopt_:     structure storing information about priors
 
 % OUTPUTS
 %   posterior_sampler_options:       checked posterior sampler options
+%   options_:       structure storing the options
+%   bayestopt_:     structure storing information about priors
 %
 % SPECIAL REQUIREMENTS
 %   none
 
-% Copyright (C) 2015-2017 Dynare Team
+% Copyright (C) 2015-2022 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -86,7 +90,6 @@ if init
                     % will overwrite jscale from set_prior.m
                     if exist(options_list{i,2},'file') || exist([options_list{i,2},'.mat'],'file')
                         tmp = load(options_list{i,2},'Scale');
-                        global bayestopt_
                         bayestopt_.mh_jscale = tmp.Scale;
                         options_.mh_jscale = tmp.Scale;
                         bayestopt_.jscale = ones(size(bounds.lb,1),1)*tmp.Scale;
@@ -152,7 +155,6 @@ if init
                     % will overwrite jscale from set_prior.m
                     if exist(options_list{i,2},'file') || exist([options_list{i,2},'.mat'],'file')
                         tmp = load(options_list{i,2},'Scale');
-                        global bayestopt_
                         bayestopt_.mh_jscale = tmp.Scale;
                         options_.mh_jscale = tmp.Scale;
                         bayestopt_.jscale = ones(size(bounds.lb,1),1)*tmp.Scale;
diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m
index 20f16b473e972d93be3e787f4c9b10be833ec7d4..7488fe21a0b1173d8169538b818db01f5bb5d9c8 100644
--- a/matlab/dynare_estimation_1.m
+++ b/matlab/dynare_estimation_1.m
@@ -465,7 +465,7 @@ if (any(bayestopt_.pshape  >0 ) && options_.mh_replic) || ...
     if options_.mh_replic || options_.load_mh_file
         posterior_sampler_options = options_.posterior_sampler_options.current_options;
         posterior_sampler_options.invhess = invhess;
-        [posterior_sampler_options, options_] = check_posterior_sampler_options(posterior_sampler_options, options_);
+        [posterior_sampler_options, options_, bayestopt_] = check_posterior_sampler_options(posterior_sampler_options, options_, bounds, bayestopt_);
         % store current options in global
         options_.posterior_sampler_options.current_options = posterior_sampler_options;
         if options_.mh_replic
diff --git a/matlab/dynare_estimation_init.m b/matlab/dynare_estimation_init.m
index 5f0af2dbdfdc5e2ccb834144031ccb64b9b05e63..d2e8f099e7ab15d1c55ecb1c58ff1ee742858aa2 100644
--- a/matlab/dynare_estimation_init.m
+++ b/matlab/dynare_estimation_init.m
@@ -649,7 +649,7 @@ if options_.load_results_after_load_mh
 end
 
 if options_.mh_replic || options_.load_mh_file
-    [current_options, options_] = check_posterior_sampler_options([], options_, bounds);
+    [current_options, options_, bayestopt_] = check_posterior_sampler_options([], options_, bounds, bayestopt_);
     options_.posterior_sampler_options.current_options = current_options;
 end