     // MARK: Drawing a path
     
     private func drawLine(a: CGPoint, b: CGPoint, buffer: UIImage?) -> UIImage {
+        let image = drawInContext { context in
+            // Draw the line
+            self.drawColor.setStroke()
+            CGContextSetLineWidth(context, self.drawWidth)
+            CGContextSetLineCap(context, kCGLineCapRound)
+            
+            CGContextMoveToPoint(context, a.x, a.y)
+            CGContextAddLineToPoint(context, b.x, b.y)
+            CGContextStrokePath(context)
+        }
+        
+        return image
+    }
+    
+    // MARK: Drawing a point
+    
+    private func drawPoint(at: CGPoint, buffer: UIImage?) -> UIImage {
+        let image = drawInContext { context in
+            // Draw the point
+            self.drawColor.setFill()
+            let circle = UIBezierPath(arcCenter: at, radius: self.drawWidth / 2.0, startAngle: 0, endAngle: 2 * CGFloat(M_PI), clockwise: true)
+            circle.fill()
+        }
+        
+        return image
+    }
+    
+    // MARK: General setup to draw. Reusing a buffer and returning a new one
+    
+    private func drawInContext(code:(context: CGContextRef) -> Void) -> UIImage {
         let size = self.bounds.size
         
         // Initialize a full size image. Opaque because we don't need to draw over anything. Will be more performant.

    // MARK: Gestures
    
    private func setupGestureRecognizers() {
        // 1. Set up a pan gesture recognizer to track where user moves finger
        let panRecognizer = UIPanGestureRecognizer(target: self, action: "handlePan:")
        self.addGestureRecognizer(panRecognizer)
    }
    
    @objc private func handlePan(sender: UIPanGestureRecognizer) {

        self.lastPoint = CGPointZero
    }
    
    // MARK: Tracking a point
    
    private func tapAtPoint(point: CGPoint) {
        autoreleasepool {
            self.buffer = self.drawPoint(point, buffer: self.buffer)
            self.layer.contents = self.buffer?.CGImage ?? nil
        }
    }
    
    var drawColor: UIColor = UIColor.blackColor()
    var drawWidth: CGFloat = 10.0
    
