             recordTouch(at: lastPoint!, withRadius: size!, thatWasMoving:false)
         } else {
             // not recording, add disappearing touches.
-            addTailSegment(at: lastPoint!, withSize: size!, thatWasMoving: false)
+            addTailSegment(at: lastPoint!, withSize: size!)
         }
         // always make a sound.
         makeSound(at: lastPoint!, withRadius: size!, thatWasMoving: false)

    
    /// Storage for a single tail segment which consists of a touch location and a timer for removing it.
    struct TailSegment {
        var touch: TouchRecord
        var timer: Timer
    }
    
    /// Add animated tail segment that removes itself after a certain time.
    private func addTailSegment(at point: CGPoint, withSize size: CGFloat, thatWasMoving moving: Bool) {
        let touch = TouchRecord(time: 0, x: Double(point.x), y: Double(point.y), z: Double(size), moving: moving)
        let timer = Timer.scheduledTimer(withTimeInterval: 0.3, repeats: false) { (timer) in
            if !self.tailSegments.isEmpty {
                self.tailSegments.removeFirst()
                self.draw(tailSegments: self.tailSegments, withColor: self.recordingColour!)
            }
        }
        let tailSegment = TailSegment(touch: touch, timer: timer)
        tailSegments.append(tailSegment)
        draw(tailSegments: tailSegments, withColor: recordingColour!) // redraw the tail segments
    }
    
    /// Draws all present tail segments. If there is a recorded image it should draw them on top of that, if not draw from nothing.
    func draw(tailSegments: [TailSegment], withColor color: CGColor) {
        UIGraphicsBeginImageContextWithOptions(frame.size, false, (UIScreen.main).scale)
        guard let context = UIGraphicsGetCurrentContext() else {
            return
        }
        
        // Get the present recorded image.
        if let presentPerf = performance,
            let image = presentPerf.image {
            image.draw(in: CGRect(x:0, y:0, width:frame.size.width, height:frame.size.height))
        }

        // Now draw all the tail segments.
        context.setFillColor(color)
        context.setStrokeColor(color)
        context.setBlendMode(CGBlendMode.normal)
        context.setLineCap(CGLineCap.round)
        context.setLineWidth(10.0)
        context.beginPath()
        
        for (i, current) in tailSegments.enumerated() {
            if i == 0 || !current.touch.moving {
                context.move(to: CGPoint(x: current.touch.x, y: current.touch.y))
            }
            context.addLine(to: CGPoint(x: current.touch.x, y: current.touch.y))
        }
        
        context.strokePath()
        image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
    }
    
}

// MARK: Pd (Sound) Functions

            recordTouch(at: currentPoint, withRadius: size!, thatWasMoving: true)
        } else {
            // not recording, add disappearing touches.
            addTailSegment(at: currentPoint, withSize: size!)
            lastPoint = currentPoint
        }
        
