         context.setFillColor(NSColor.white.cgColor)
         context.fill(self.bounds)
         
-        Draw.drawSkeleton(context, curve: curve)
-        Draw.drawCurve(context, curve: curve)
+        Draw.drawSkeleton(context, curve: curve!)
+        Draw.drawCurve(context, curve: curve!)
         
     }
     

    required init?(coder: NSCoder) {
        NSLog("init with coder")
        
        self.curve = CubicBezier(p0: BKPoint(x: 100, y: 25),
                                 p1: BKPoint(x: 10, y: 90),
                                 p2: BKPoint(x: 110, y: 100),
                                 p3: BKPoint(x: 150, y: 195))

        super.init(coder: coder)
        
    }
    
    override func draw(_ dirtyRect: NSRect) {


import AppKit

typealias DraggableCallback = (_ dragPosition: BKPoint) -> (BKPoint)

protocol DraggableDelegate: class {
    func draggable(_ draggable: Draggable, didUpdateLocation location: BKPoint)
}

class Draggable {
    
    var location: BKPoint
    weak var delegate: DraggableDelegate?
    private let callback: DraggableCallback
    private let radius: Double
    
    init(initialLocation location: BKPoint, radius: Double, callback: @escaping DraggableCallback) {
        self.location = location
        self.radius = radius
        self.callback = callback
    }
    convenience init(initialLocation location: BKPoint, radius: Double) {
        
        let callback: DraggableCallback = { (dragPosition: BKPoint) -> (BKPoint) in
            return dragPosition
        }
        self.init(initialLocation: location, radius: radius, callback: callback)
        
    }
    func updateLocation(_ location: BKPoint) {
        let updatedLocation = self.callback(location)
        if self.location.equalTo(updatedLocation) == false {
            self.location = updatedLocation
            self.delegate!.draggable(self, didUpdateLocation: updatedLocation)
        }
    }
    func containsLocation(_ location: BKPoint) -> Bool {
        let c = self.cursorRect as CGRect
        print("%@ contains location %@", self.cursorRect, location)
        return c.contains(location)
    }
    
    var cursorRect: NSRect {
        get {
            let r = self.radius
            let r2 = 2.0 * r
            return CGRect( origin: self.location - CGPoint(x: r, y: r),
                           size: CGSize(width: r2, height: r2))
        }
    }
    
}

class DemoView: NSView, DraggableDelegate {
    
    var curve: CubicBezier?
    
    var draggables: [Draggable]
    var selectedDraggable: Draggable?
    
    var cp0: Draggable?
    var cp1: Draggable?
    var cp2: Draggable?
    var cp3: Draggable?

    override var isFlipped: Bool {
        get {
            return true
