Bunch of updates to fitting functions, but not a match to matlab