Fitting with three functions