Refactored methods for simpler code. Introduced piecewise polynomial interpolation.