refactored spline algorithm