B-spline fitting