improve the speed of the fit a bit, but still there is a memory leak somewhere