modelfit_mg function started