function [x_5,x_6]=wrapper_function(X,M_,options_,oo_,var_list_)

%set paraemters in M_
M_.params(strmatch('ppsipi',M_.param_names,'exact'))= X(1);
M_.params(strmatch('ppsiy',M_.param_names,'exact'))= X(2);
M_.params(strmatch('rrhor',M_.param_names,'exact'))= X(3);
M_.params(strmatch('ppibar',M_.param_names,'exact'))= X(4);

%get decision rules
[dr,info,M_,oo_] = resol(0,M_,options_,oo_);
if info(1) %problem
    x_5 = -Inf;  %%set welfare to NAN if indeterminate and move onto next loop
    x_6 = NaN;
else
    %get moments
    oo_=disp_th_moments(oo_.dr,var_list_,M_,options_,oo_);
    Welf_pos=strmatch('Welf',M_.endo_names,'exact');
    R_pos=strmatch('R',var_list_,'exact');
    %x_5 = oo_.dr.ys(Welf_pos) + oo_.dr.ghs2(oo_.dr.inv_order_var(Welf_pos))/2; %%my definition of welfare instead of using oo_.mean(10) which is stochastic SS of Welf.
    x_6 = oo_.mean(R_pos)- 2*sqrt(oo_.var(R_pos,R_pos));   %%I say this condition on R must be satisfied for welfare to count.
    x_5=csolve('get_consumption_equivalent_conditional_welfare',0,[],1e-8,1000,M_, options_, oo_);
end

end
