function [good_timestep, timestep, cmpd_vals] = check_last_timestep(num_cmpds, cmpd_vals, timestep, timestep_max, num_grps)

if num_grps == 1
    good_timestep = 1;
    return
end

max_change_factor = 0;
neg_cmpd_num = 0;
good_timestep = 0;

for i = 1:num_cmpds
    orig_cmpd_num = cmpd_vals(i,1);
    putative_cmpd_num = orig_cmpd_num + cmpd_vals(i,2);
    
%    eval(['global ' cmpd_list{i}{1}]) 
%    eval(['orig_cmpd_num = ' cmpd_list{i}{1} '(1);'])
%    eval(['putative_cmpd_num = sum(' cmpd_list{i}{1} '(1:2));'])
    
    change_cmpd_num = abs(putative_cmpd_num - orig_cmpd_num);
    max_cmpd_num = max([putative_cmpd_num orig_cmpd_num]);
    
    if putative_cmpd_num < 0
        neg_cmpd_num = 1
    end
    if max_cmpd_num >= 0 & max_cmpd_num <= 4
        this_change_factor = 0;
    else
        this_change_factor = change_cmpd_num ./ max_cmpd_num;
    end
        
    max_change_factor = max([max_change_factor this_change_factor]);
end
    
if max_change_factor > 1.0 | neg_cmpd_num == 1
    neg_cmpd_num = 0;
    if (1.5 + max_change_factor) < 2
        timestep = timestep ./ 2
    else
        timestep = timestep ./ (1.5 + max_change_factor)
    end
    % wipe out changes from this attempted timestep
    for i = 1:num_cmpds
        cmpd_vals(i,2) = 0;
%        eval([cmpd_list{i}{1} '(2) = 0;'])
    end
        
else
    % accept this timestep
    good_timestep = 1;
    if max_change_factor < 0.5
        timestep = timestep .* 2;
        if timestep > timestep_max
            timestep = timestep_max;
        end
    end
    
    
end
