implemnting algorithm for splines