cleaned up modelfit function