fixing the piecewise lin fit