reorganized and applied some optimizations to the spline inverter