diff --git a/matlab/check_model.m b/matlab/check_model.m
index 7e15d8d1c7523e4e2978b2a5ff4d6b29f275e257..8ab34e39312bc7e05e30cad716c3cafbb521f6a2 100644
--- a/matlab/check_model.m
+++ b/matlab/check_model.m
@@ -1,4 +1,4 @@
-function check_model()
+function check_model(DynareModel)
 
 % Copyright (C) 2005-2011 Dynare Team
 %
@@ -17,10 +17,8 @@ function check_model()
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
-global M_
-
-xlen = M_.maximum_exo_lag+M_.maximum_exo_lead + 1;
-if ~ M_.lead_lag_incidence(M_.maximum_lag+1,:) > 0
+xlen = DynareModel.maximum_exo_lag+DynareModel.maximum_exo_lead + 1;
+if ~ DynareModel.lead_lag_incidence(DynareModel.maximum_lag+1,:) > 0
     error ('RESOL: Error in model specification: some variables don"t appear as current') ;
 end
 
@@ -29,8 +27,7 @@ if xlen > 1
             ' current period. Use additional endogenous variables']) ;
 end
 
-if (M_.exo_det_nbr > 0) && (M_.maximum_lag > 1 || M_.maximum_lead > 1)
+if (DynareModel.exo_det_nbr > 0) && (DynareModel.maximum_lag > 1 || DynareModel.maximum_lead > 1)
     error(['Exogenous deterministic variables are currently only allowed in' ...
            ' models with leads and lags on only one period'])
-end
-
+end
\ No newline at end of file
diff --git a/matlab/stoch_simul.m b/matlab/stoch_simul.m
index b3eb9913f83d163b5a9a1d01fdf531c5086726bc..8370f77fde6cdd83f9fb46a3d4763d1c33c4be3b 100644
--- a/matlab/stoch_simul.m
+++ b/matlab/stoch_simul.m
@@ -60,7 +60,7 @@ if M_.exo_nbr > 0
     oo_.exo_simul= ones(iter_ + M_.maximum_lag + M_.maximum_lead,1) * oo_.exo_steady_state';
 end
 
-check_model;
+check_model(M_);
 
 oo_.dr=set_state_space(dr,M_);
 
diff --git a/matlab/stoch_simul_sparse.m b/matlab/stoch_simul_sparse.m
index 7be80a78b10c79fbceae7886dd047a7fb1f2894d..eaa6e5764ca961a6d27b640d5cc2c5a5ac086a91 100644
--- a/matlab/stoch_simul_sparse.m
+++ b/matlab/stoch_simul_sparse.m
@@ -36,7 +36,7 @@ if M_.exo_nbr > 0
     oo_.exo_simul= ones(iter_ + M_.maximum_lag + M_.maximum_lead,1) * oo_.exo_steady_state';
 end
 
-check_model;
+check_model(M_);
 
 [oo_.dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_);