fitting using least squares