Fixed the interpolation calculations to check for the edge cases better.