             {
                 cur = entries[entries.count - 1];
                 prev = entries[entries.count - 2];
-                prevPrev = entries[entries.count - 3];
+                prevPrev = entries[entries.count - (entries.count >= 3 ? 3 : 2)];
                 next = cur;
                 
                 prevDx = CGFloat(cur.xIndex - prevPrev.xIndex) * intensity;

            prevDx = CGFloat(next.xIndex - cur.xIndex) * intensity;
            prevDy = CGFloat(next.value - cur.value) * intensity;
            
            cur = entries[1];
            next = entries[2];
            curDx = CGFloat(next.xIndex - prev.xIndex) * intensity;
            curDy = CGFloat(next.value - prev.value) * intensity;
            

        
        if (dataSet.isDrawFilledEnabled)
        {
            drawCubicFill(context: context, dataSet: dataSet, spline: cubicPath, matrix: valueToPixelMatrix, from: minx, to: size);
        }
        
        CGContextBeginPath(context);
