     
     func updateAnimationFrame() {
         if maxFrames <= 0 {
-            maxFrames = Int(animationDuration / displayLink.duration);
+            if let displayLink = displayLink {
+                maxFrames = Int(animationDuration / displayLink.duration);
+            }
         }
         
         let pCur = endpoints_scaled[_currentDigit];

        if currentFrame > maxFrames {
            currentFrame = 1;
            currentDigit = _nextDigit;
            displayLink.paused = true;
            drawDigitWithoutAnimation(currentDigit);
        }
    }

        self.layer.addSublayer(shapeLayer);
        
        displayLink = CADisplayLink(target: self, selector: #selector(NumberMorphView.updateAnimationFrame));
        displayLink?.frameInterval = 1;
        displayLink?.paused = true;
        displayLink?.addToRunLoop(NSRunLoop.currentRunLoop(), forMode: NSRunLoopCommonModes);
        
        endpoints_original[0] = [[500, 800], [740, 400], [500, 0],   [260, 400], [500, 800]];
        endpoints_original[1] = [[383, 712], [500, 800], [500, 0],   [500, 800], [383, 712]];
