refactoring/improving interpolation code