Refactor cubic spline derivation