diff --git a/matlab/metropolis_hastings_initialization.m b/matlab/metropolis_hastings_initialization.m
index b248ad2542e0ea8094019756fd9b2b526cff3ad3..5b5f255626ac06ebc73eaf592f2eef52b14e36cd 100644
--- a/matlab/metropolis_hastings_initialization.m
+++ b/matlab/metropolis_hastings_initialization.m
@@ -59,8 +59,6 @@ if ~isempty(M_.bvar)
     ModelName = [M_.fname '_bvar'];
 end
 
-bayestopt_.penalty = Inf;
-
 MhDirectoryName = CheckPath('metropolis',M_.dname);
 
 nblck = options_.mh_nblck;
@@ -113,7 +111,8 @@ if ~options_.load_mh_file && ~options_.mh_recover
                 if all(candidate(:) > mh_bounds(:,1)) && all(candidate(:) < mh_bounds(:,2)) 
                     ix2(j,:) = candidate;
                     ilogpo2(j) = - feval(TargetFun,ix2(j,:)',dataset_,options_,M_,estim_params_,bayestopt_,oo_);
-                    if ilogpo2(j) <= - bayestopt_.penalty+1e-6
+                    if ~isfinite(ilogpo2(j)) % if returned log-density is
+                                             % Inf or Nan (penalized value)
                         validate = 0;
                     else
                         fprintf(fidlog,['    Blck ' int2str(j) ':\n']);
diff --git a/matlab/random_walk_metropolis_hastings.m b/matlab/random_walk_metropolis_hastings.m
index c5e982921ce007d0940ad35bffb7c4ebaa1c7da1..6e5d782d4428e6983d73bd36524dc99f4a6df484 100644
--- a/matlab/random_walk_metropolis_hastings.m
+++ b/matlab/random_walk_metropolis_hastings.m
@@ -56,6 +56,12 @@ function record=random_walk_metropolis_hastings(TargetFun,ProposalFun,xparam1,vv
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
+
+% In Metropolis, we set penalty to Inf to as to reject all parameter sets
+% triggering error in target density computation
+
+bayestopt_.penalty = Inf;
+
 %%%%
 %%%% Initialization of the random walk metropolis-hastings chains.
 %%%%
diff --git a/matlab/random_walk_metropolis_hastings_core.m b/matlab/random_walk_metropolis_hastings_core.m
index 8bb4d44b1bcc268d5f0d4fbfa65189e25156ae87..84f180c97d2472782fd05a37f4755c49155a0ef0 100644
--- a/matlab/random_walk_metropolis_hastings_core.m
+++ b/matlab/random_walk_metropolis_hastings_core.m
@@ -103,9 +103,6 @@ if whoiam
         bayestopt_.p3,bayestopt_.p4,1);
 end
 
-% (re)Set the penalty
-bayestopt_.penalty = Inf;
-
 MhDirectoryName = CheckPath('metropolis',M_.dname);
 
 options_.lik_algo = 1;