refactoring interpolation code