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

            recordTouch(at: lastPoint!, withRadius: size!, thatWasMoving:false)
        } else {
            // not recording, add disappearing touches.
            addTailSegment(at: lastPoint!, withSize: size!, thatWasMoving: false)
        }
        // 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 point: CGPoint
        var size: CGFloat
        var layer: CALayer?
        var timer: Timer
    }
    
    /// Add animated tail segment that removes itself after a certain time.
    private func addTailSegment(at point: CGPoint, withSize size: CGFloat) {
        // make a timer to self destruct the segment.
        let timer = Timer.scheduledTimer(withTimeInterval: 0.3, repeats: false) { (timer) in
            self.removeOldestTailSegment() // remove the oldest segment
        }
        
        // figure out last point, if no previous segment, just use same point.
        var lastPoint = point
        if let seg = tailSegments.last {
            lastPoint = seg.point
        }
        
        // make a CALayer for the segment
        let tailLayer = makeSegmentLayer(from: lastPoint, to: point, withColour: self.recordingColour ?? DEFAULT_RECORDING_COLOUR)
        
        // make a struct for the segment
        let tailSegment = TailSegment(point: point, size: size, layer: tailLayer, timer: timer)
        tailSegments.append(tailSegment) // add to storage
        layer.addSublayer(tailLayer) // draw the tail segment
    }
    
    /// Draw a tail segment returning a CALayer
    func makeSegmentLayer(from: CGPoint, to: CGPoint, withColour color: CGColor) -> CALayer {
        let line = CAShapeLayer()
        let linePath = UIBezierPath()
        linePath.move(to: from)
        linePath.addLine(to: to)
        line.path = linePath.cgPath
        line.lineCap = .round
        line.lineWidth = 10.0
        line.fillColor = nil
        line.opacity = 1.0
        line.strokeColor = color
        return line
    }
    
    /// A timed function to remove the oldest tail segment from the stored list.
    func removeOldestTailSegment() {
        if let seg = self.tailSegments.first {
            self.tailSegments.removeFirst() // remove from array
            seg.layer?.removeFromSuperlayer() // remove layer from view
            seg.timer.invalidate() // cancel the timer
        }
    }
}

// MARK: Pd (Sound) Functions
