added segmented Least squares