function [fit_distance, optimal_value_holder]=template_loop_diver(values,live_values,live_ranges,i,fit_distance,optimal_value_holder,real_data,tfs,current_parameter_vals)

for i=1:length(live_values)  
    if i==length(live_values)
        eval('tfs') %template_function_string
        new_fit_distance=fit_comparison_lsq(real_data(1:length(template)), template);
        if new_fit_distance<fit_distance,
            fit_distance=new_fit_distance;
            for i=1:length(live_values);
                optimal_value_holder(i)=eval(values{live_values(i)});
			end
        end
        current_parameter_values(i)=current_parameter_values(i)+1;
        
    else
       %eval(['for ' values{i} '=' num2str(live_ranges(2,live_values(i))) ':' num2str'live_ranges(3,live_values(i))'])
       
       [fit_distance, optimal_value_holder,current_parameter_vals]=template_loop_diver(values,live_values,live_ranges,i,fit_distance,optimal_value_holder,real_data,tfs,current_parameter_vals)
	end
end