 import AppKit
 
 public class JSSwitch: NSControl {
-	public override var wantsUpdateLayer: Bool {
-		return true
-	}
-	public override var intrinsicContentSize: NSSize {
-		return CGSize(width: 52, height: 32)
-	}
-
+	// MARK: - Properties
 	private var pressed = false
-	private let baseHeight: CGFloat = 62
 	private let backgroundLayer = CALayer()
 	private let knobContainer = CALayer()
 	private let knobLayer = CALayer()
 	private let knobShadows = (smallStroke: CALayer(), smallShadow: CALayer(), mediumShadow: CALayer(), bigShadow: CALayer())
 
-	public var tintColor = NSColor(deviceRed: 104/255, green: 218/255, blue: 113/255, alpha: 1.0) {
+	// MARK: Computed
+	public override var wantsUpdateLayer: Bool { return true }
+	public override var intrinsicContentSize: NSSize {
+		return CGSize(width: 52, height: 32)
+	}
+
+	private var scaleFactor: CGFloat {
+		return ceil(frame.size.height / 62) // Hardcoded base height
+	}
+
+	public var tintColor = NSColor(deviceRed: 76/255, green: 217/255, blue: 100/255, alpha: 1.0) {
 		didSet { needsDisplay = true }
 	}
 	public var on = false {

	}

	private func setupKnobLayer() {
		knobLayer.autoresizingMask = [.LayerWidthSizable]
		knobLayer.backgroundColor = NSColor.whiteColor().CGColor
		knobLayer.frame = knobContainer.bounds
		knobLayer.cornerRadius = ceil(knobContainer.bounds.height / 2)
	}

	private func setupKnobLayerShadows() {
		let effectScale = backgroundLayer.bounds.height / baseHeight
		// Small Stroke
		let smallStroke = knobShadows.smallStroke
		smallStroke.frame = knobLayer.frame.insetBy(dx: -1, dy: -1)
		smallStroke.autoresizingMask = [.LayerWidthSizable]
		smallStroke.backgroundColor = NSColor.blackColor().colorWithAlphaComponent(0.06).CGColor
		smallStroke.cornerRadius = ceil(smallStroke.bounds.height / 2)

		let smallShadow = knobShadows.smallShadow
		smallShadow.frame = knobLayer.frame.insetBy(dx: 2, dy: 2)
		smallShadow.autoresizingMask = [.LayerWidthSizable]
		smallShadow.cornerRadius = ceil(smallShadow.bounds.height / 2)
		smallShadow.backgroundColor = NSColor.redColor().CGColor
		smallShadow.shadowColor = NSColor.blackColor().CGColor
		smallShadow.shadowOffset = CGSize(width: 0, height: -3 * effectScale)
		smallShadow.shadowOpacity = 0.12
		smallShadow.shadowRadius = 2.0 * effectScale

		let mediumShadow = knobShadows.mediumShadow
		mediumShadow.frame = smallShadow.frame
		mediumShadow.autoresizingMask = [.LayerWidthSizable]
		mediumShadow.cornerRadius = smallShadow.cornerRadius
		mediumShadow.backgroundColor = NSColor.redColor().CGColor
		mediumShadow.shadowColor = NSColor.blackColor().CGColor
		mediumShadow.shadowOffset = CGSize(width: 0, height: -9 * effectScale)
		mediumShadow.shadowOpacity = 0.16
		mediumShadow.shadowRadius = 6.0 * effectScale

		let bigShadow = knobShadows.bigShadow
		bigShadow.frame = smallShadow.frame
		bigShadow.autoresizingMask = [.LayerWidthSizable]
		bigShadow.cornerRadius = smallShadow.cornerRadius
		bigShadow.backgroundColor = NSColor.redColor().CGColor
		bigShadow.shadowColor = NSColor.blackColor().CGColor
		bigShadow.shadowOffset = CGSize(width: 0, height: -9 * effectScale)
		bigShadow.shadowOpacity = 0.06
		bigShadow.shadowRadius = 0.5 * effectScale

	private func setupLayers() {
		wantsLayer = true
		layer?.masksToBounds = false
		layerContentsRedrawPolicy = .onSetNeedsDisplay

		// Background
		setupBackgroundLayer()
