     
     /// clears the UIImageViews
     private func internalClear() -> Void {
-        mainImageView.image = nil
-        tempImageView.image = nil
+        self.mainImageView.image = nil
+        self.tempImageView.image = nil
     }
     
     /// clears the drawing
     public func clearDrawing() -> Void {
-        internalClear()
-        touchDrawUndoManager!.registerUndoWithTarget(self, selector: #selector(TouchDrawView.pushAll(_:)), object: stack)
-        stack = []
-        
-        checkClearState()
-        
-        if !touchDrawUndoManager!.canRedo {
-            if redoEnabled {
-                delegate.redoDisabled()
-                redoEnabled = false
+        self.internalClear()
+        self.touchDrawUndoManager!.registerUndoWithTarget(self, selector: #selector(TouchDrawView.pushAll(_:)), object: stack)
+        self.stack = []
+        
+        self.checkClearState()
+        
+        if !self.touchDrawUndoManager!.canRedo {
+            if self.redoEnabled {
+                self.delegate?.redoDisabled?()
+                self.redoEnabled = false
             }
         }
     }

            // Draw the one point
            let pointStr = array[0] 
            let point = CGPointFromString(pointStr)
            drawLineFrom(point, toPoint: point, properties: properties)
        }
        
        for i in 0 ..< array.count - 1 {


    /// adds the subviews and initializes stack
    private func initTouchDrawView(frame: CGRect) {
        self.addSubview(self.mainImageView)
        self.addSubview(self.tempImageView)
        self.stack = []
        
        self.touchDrawUndoManager = undoManager
        if self.touchDrawUndoManager == nil {
            self.touchDrawUndoManager = NSUndoManager()
        }
        
        // Initially sets the frames of the UIImageViews
        self.drawRect(frame)
    }
    
    /// sets the frames of the subviews
    override public func drawRect(rect: CGRect) {
        self.mainImageView.frame = rect
        self.tempImageView.frame = rect
    }
    
    /// merges tempImageView into mainImageView
    private func mergeViews() {
        UIGraphicsBeginImageContext(self.mainImageView.frame.size)
        self.mainImageView.image?.drawInRect(self.mainImageView.frame, blendMode: CGBlendMode.Normal, alpha: 1.0)
        self.tempImageView.image?.drawInRect(self.tempImageView.frame, blendMode: CGBlendMode.Normal, alpha: self.brushProperties.color.alpha)
        
        let image = UIGraphicsGetImageFromCurrentImageContext()
        self.mainImageView.image = image
        UIGraphicsEndImageContext()
        
        self.tempImageView.image = nil
    }
    
    /// removes the last stroke from stack
    internal func popDrawing() {
        let stroke = stack.last
        self.stack.popLast()
        self.redrawLinePathsInStack()
        self.touchDrawUndoManager!.registerUndoWithTarget(self, selector: #selector(TouchDrawView.pushDrawing(_:)), object: stroke)
    }
    
    /// adds a new stroke to the stack
    internal func pushDrawing(object: AnyObject) {
        let stroke = object as? Stroke
        self.stack.append(stroke!)
        self.drawLine(stroke!)
        self.touchDrawUndoManager!.registerUndoWithTarget(self, selector: #selector(TouchDrawView.popDrawing), object: nil)
    }
    
    /// draws all the lines in the stack
    private func redrawLinePathsInStack() {
        self.internalClear()
        
        for stroke in self.stack {
            self.drawLine(stroke)
        }
    }
    
