Fixed bug in fit_model function