             let offset = style.tabButtonOffset(position: button.buttonPosition)
             let buttonFrame = CGRectMake(buttonX + offset.x, offset.y, buttonWidth, buttonHeight)
             buttonX += buttonWidth + offset.x
-            
+
+            button.layer?.zPosition = button.state == NSOnState ? CGFloat(FLT_MAX) : CGFloat(index)
+
             if animated && !button.hidden {
                 button.animator().frame = buttonFrame
             } else {
                 button.frame = buttonFrame
             }
             
-            if let delegateReceiver = self.delegateInterceptor.receiver as? TabsControlDelegate {
-                if delegateReceiver.tabsControl?(self, canSelectItem: button.tabButtonCell!.representedObject!) != nil {
-                    button.tabButtonCell!.selectable = delegateReceiver.tabsControl!(self, canSelectItem: button.tabButtonCell!.representedObject!)
-                    // TODO: not entirely sure this swift code does what I want... fix that.
-                }
-            }
-            
-            button.tag = index
+            if let delegateReceiver = self.delegateInterceptor.receiver as? TabsControlDelegate
+                where delegateReceiver.tabsControl?(self, canSelectItem: button.tabButtonCell!.representedObject!) != nil {
+
+                button.tabButtonCell!.selectable = delegateReceiver.tabsControl!(self, canSelectItem: button.tabButtonCell!.representedObject!)
+                // TODO: not entirely sure this swift code does what I want... fix that.
+            }
+
             tabsViewWidth += buttonWidth
         }
 

        defer { self.reloadTabs() }
        
        guard !newValue.isEmpty
            && self.delegate?.tabsControl?(self, setTitle: newValue, forItem: tabButton.representedObject!) != nil else { return }
        
        // TODO add callback to client code to replace forwarding controlTextDidEndEditing(_:)
        
        tabButton.representedObject = self.dataSource?.tabsControl(self, itemAtIndex: self.selectedItemIndex)
    }

    // MARK: - Drawing

    private var addButton: NSButton? = nil
    private var scrollLeftButton: NSButton? = nil
    private var scrollRightButton: NSButton? = nil
    private var selectedButton: TabButton? = nil

    private var hideScrollButtons: Bool = true
//    private var isHighlighted: Bool = false
