rewrite leastsq fit as a single function