 		guard let endTouch = touch else { return }
         updateForTouch(endTouch, modifyHue: touchInside)
         removePreview()
-        
-        if touchInside {
-            sendActionsForControlEvents(.TouchUpInside)
-        } else {
-            sendActionsForControlEvents(.TouchUpOutside)
-        }
+		
+		sendActionsForControlEvents(touchInside ? .TouchUpInside : .TouchUpOutside)
     }
     
     public override func cancelTrackingWithEvent(event: UIEvent?) {
         sendActionsForControlEvents(.TouchCancel)
     }
     
-    private func updateForTouch (touch: UITouch, modifyHue: Bool) {
+    private func updateForTouch(touch: UITouch, modifyHue: Bool) {
         if modifyHue {
-            // Modify the hue at constant lightness
+            // Modify hue at constant lightness
             let locationInView = touch.locationInView(self)
-            // TODO: Horizontal mode
-            if orientation == .Vertical {
-                hue = 1 - min(1, max(0, (locationInView.y / frame.height)))
-            } else if orientation == .Horizontal {
-                hue = 1 - min(1, max(0, (locationInView.x / frame.width)))
-            }
+			let top = orientation == .Vertical ? locationInView.y : locationInView.x
+			let bottom = orientation == .Vertical ? frame.height : frame.width
+			hue = 1 - min(1, max(0, (top / bottom)))
             lightness = 0.5
         } else {
-            // Modify the lightness for the current hue
-            let locationInSuperview = touch.locationInView(self.superview)
-            // TODO: Horizontal mode
-            if orientation == .Vertical {
-                lightness = 1 - (locationInSuperview.y / superview!.frame.height)
-            } else if orientation == .Horizontal {
-                lightness = 1 - (locationInSuperview.x / superview!.frame.width)
-            }
-        }
-    }
-    
-    public override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
-        // Expand the touch size to be as wide/tall as normal control
-        let idealTouchDimenson: CGFloat = 30
-        if orientation == .Vertical {
-            let widthDiff = (idealTouchDimenson - frame.size.width) / 2
-            let widthPad = widthDiff > 0 ? widthDiff : 0
-            let expandedRect = CGRectInset(bounds, -widthPad, 0)
-            return CGRectContainsPoint(expandedRect, point)
-        } else {
-            let heightDiff = (idealTouchDimenson - frame.size.height) / 2
-            let heightPad = heightDiff > 0 ? heightDiff : 0
-            let expandedRect = CGRectInset(bounds, 0, -heightPad)
-            return CGRectContainsPoint(expandedRect, point)
-        }
-    }
-    
-    // MARK: Appearance
+            // Modify lightness for the current hue
+			guard let _superview = superview else { return }
+			let locationInSuperview = touch.locationInView(_superview)
+			let top = orientation == .Vertical ? locationInSuperview.y : locationInSuperview.x
+			let bottom = orientation == .Vertical ? _superview.frame.height : _superview.frame.width
+			lightness = 1 - (top / bottom)
+        }
+    }
+	
+    // MARK: - Appearance
     public override func drawRect(rect: CGRect) {
         super.drawRect(rect)
         

        }
    }
    
    // MARK: - Color Preview popup
    var previewDimension: CGFloat = 32
    var previewAnimationDuration = 0.15
    func showPreviewPopup(touch: UITouch) {
        // Currently, this method needs to be called _after_ updateForTouch
        // Create the preview view, set shape
        let preview = UIView(frame: CGRect(x: 0, y: 0, width: previewDimension, height: previewDimension))
        preview.layer.cornerRadius = previewDimension/2
        previewView = preview
        
        // Initialize preview in proper position, save frame
        updatePreview(touch)
        let endFrame = preview.frame
        
        // Get frame for animation, set as current frame to navigate _from_
        let startFrame = animationPositionForPreview(endFrame)
        preview.frame = startFrame
        
        addSubview(preview)
        UIView.animateWithDuration(previewAnimationDuration, delay: 0, options: [.BeginFromCurrentState, .CurveEaseInOut], animations: { () -> Void in
            preview.frame = endFrame
            preview.layer.cornerRadius = self.previewDimension/2
		}, completion: nil)
        
        let cornerAnimation = CABasicAnimation(keyPath: "cornerRadius")
        cornerAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
        cornerAnimation.fromValue = startFrame.size.height/2
        cornerAnimation.toValue = previewDimension/2
        cornerAnimation.duration = previewAnimationDuration
        preview.layer.addAnimation(cornerAnimation, forKey: "cornerRadius")
    }
    
    func updatePreview(touch: UITouch) {
        if let preview = previewView {
            let frame = positionForPreview(touch)
            preview.frame = frame
            preview.backgroundColor = color
        }
    }
    
    func removePreview() {
        if let preview = previewView {
            // Move to bar for animation
            let endFrame = animationPositionForPreview(preview.frame)
            
            UIView.animateWithDuration(previewAnimationDuration, delay: 0, options: [.BeginFromCurrentState, .CurveEaseInOut], animations: { () -> Void in
                preview.frame = endFrame
                }, completion: { (completed: Bool) -> Void in
                    preview.removeFromSuperview()
                    self.previewView = nil
            })
            let cornerAnimation = CABasicAnimation(keyPath: "cornerRadius")
            cornerAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
            cornerAnimation.toValue = endFrame.size.height/2
            cornerAnimation.fromValue = previewDimension/2
            cornerAnimation.duration = previewAnimationDuration
            preview.layer.addAnimation(cornerAnimation, forKey: "cornerRadius")
        }
    }
    
    func positionForPreview(touch: UITouch) -> CGRect {
        let location = touch.locationInView(self)
        
        if orientation == .Vertical {
            var y = location.y - (previewDimension/2)
            // Prevent preview from running past bounds
            if y < 0 { y = 0}
            if y + previewDimension > CGRectGetHeight(bounds) {y = CGRectGetHeight(bounds) - previewDimension }
            
            let x = -(previewDimension + 8)
            let frameInBounds = CGRect(x: x, y: y, width: previewDimension, height: previewDimension)
            return frameInBounds
        } else {
            var x = location.x - (previewDimension/2)
            // Prevent preview from running past bounds
            if x < 0 { x = 0}
            if x+previewDimension > CGRectGetWidth(bounds) { x = CGRectGetWidth(bounds) - previewDimension }
            
            let y = -(previewDimension + 8)
            let frameInBounds = CGRect(x: x, y: y, width: previewDimension, height: previewDimension)
            return frameInBounds
        }
    }
    
    func animationPositionForPreview(position: CGRect) -> CGRect {
        let animationSize: CGFloat = 5.0
        if orientation == .Vertical {
            let animationY = position.origin.y + ((previewDimension - animationSize) / 2)
            let animationFrame = CGRect(x: CGRectGetWidth(bounds) / 2, y: animationY, width: animationSize, height: animationSize)
            return animationFrame
        } else {
            let animationX = position.origin.x + ((previewDimension - animationSize) / 2)
            let animationFrame = CGRect(x: animationX, y: CGRectGetHeight(bounds) / 2, width: animationSize, height: animationSize)
            return animationFrame
        }
    }
}

public extension UIColor {
    // Adapted from https://github.com/thisandagain/color

        }
    }
    @IBInspectable public var borderWidth: CGFloat = 1.0 {
        didSet { drawLayer.borderWidth = borderWidth }
    }
    @IBInspectable public var borderColor: UIColor = UIColor.blackColor() {
        didSet { drawLayer.borderColor = borderColor.CGColor }
    }
    @IBInspectable public var shadowOpacity: Float = 0.0 {
        didSet { drawLayer.shadowOpacity = shadowOpacity }
    }
    @IBInspectable public var shadowRadius: CGFloat = 0.0 {
        didSet { drawLayer.shadowRadius = shadowRadius }
    }
    @IBInspectable public var shadowColor: UIColor = UIColor.clearColor() {
        didSet { drawLayer.shadowColor = shadowColor.CGColor }
    }
    public var shadowOffset: CGSize = CGSizeMake(0.0, 0.0) {
        didSet { drawLayer.shadowOffset = shadowOffset }
    }
    @IBInspectable private var shadowOffsetX: CGFloat = 0.0 {
        didSet { drawLayer.shadowOffset = CGSizeMake(shadowOffsetX, shadowOffsetY) }
    }
    @IBInspectable private var shadowOffsetY: CGFloat = 0.0 {
        didSet { drawLayer.shadowOffset = CGSizeMake(shadowOffsetX, shadowOffsetY) }
    }
    
    public var orientation: ColorSliderOrientation = .Vertical {
        didSet {
            switch orientation {
				case .Vertical:
					drawLayer.startPoint = CGPointMake(0.5, 1)
					drawLayer.endPoint = CGPointMake(0.5, 0)
				case .Horizontal:
					drawLayer.startPoint = CGPointMake(0, 0.5)
					drawLayer.endPoint = CGPointMake(1, 0.5)
			}
		}
	}
	
    // MARK: Internal properties
    private var drawLayer: CAGradientLayer = CAGradientLayer()
    private var hue: CGFloat = 0.0
    private var lightness: CGFloat = 0.5
	
	// MARK: Preview view
	@IBInspectable public var previewEnabled: Bool = false
    private var previewView: UIView = UIView()
	private let previewDimension: CGFloat = 32
	private let previewAnimationDuration: NSTimeInterval = 0.15
	
    // MARK: - Initializers
	convenience init() {
        self.init()
       	commonInit()
    }
    
    public override init(frame: CGRect) {
        super.init(frame: frame)
        commonInit()
    }
    
    public required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
		commonInit()
    }
	
	func commonInit() {
		backgroundColor = UIColor.clearColor()
		clipsToBounds = false
		
		previewView.clipsToBounds = true
		previewView.layer.cornerRadius = previewDimension / 2
	}
	
    // MARK: - UIControl methods
    public override func beginTrackingWithTouch(touch: UITouch, withEvent event: UIEvent?) -> Bool {
        super.beginTrackingWithTouch(touch, withEvent: event)
        
        updateForTouch(touch, modifyHue: true)
        showPreview(touch)
        
        sendActionsForControlEvents(.TouchDown)
        return true
