     }
     
     var spacersEnabled: Bool {
-        return distr == .EqualSpacing
+        return type == .EqualSpacing
     }
     
     func updateCanvasConnectingCostraints() {
-        guard let first = canvas.arrangedSubviews.first, last = canvas.arrangedSubviews.last else {
+        guard let first = views.first, last = views.last else {
             return
         }
-        let leadingEdge: ALEdge = hor ? .Leading : .Top
-        let trailingEdge: ALEdge = hor ? .Trailing : .Bottom
+        let leadingEdge: ALEdge = horizontal ? .Leading : .Top
+        let trailingEdge: ALEdge = horizontal ? .Trailing : .Bottom
         if marginsEnabled {
             constraints.append(first.autoPinEdgeToSuperviewMargin(leadingEdge))
             constraints.append(last.autoPinEdgeToSuperviewMargin(trailingEdge))

        }
        // Configure spacers
        let _ = spacers.reduce(nil as Spacer?) { previous, current in
            let dimension: ALDimension = hor ? .Width : .Height
            constraints.append(current.autoSetDimension(dimension, toSize: spacing, relation: (distr == .EqualSpacing ? .Equal : .GreaterThanOrEqual)))
            if let previous = previous {
                constraints.append(current.autoMatchDimension(dimension, toDimension: dimension, ofView: previous))
            }

    // MARK: Layout
    
    private func invalidateLayout() {
        if !invalidated {
            invalidated = true
            setNeedsUpdateConstraints()
        }
    }
    
    public override func updateConstraints() {
        if invalidated {
            invalidated = false
            
            alignmentArrangement.views = arrangedSubviews
            alignmentArrangement.axis = axis
            alignmentArrangement.marginsEnabled = layoutMarginsRelativeArrangement
            
            alignmentArrangement.type = alignment
            
            distributionArrangement.views = arrangedSubviews
            distributionArrangement.axis = axis
            distributionArrangement.marginsEnabled = layoutMarginsRelativeArrangement
            
            distributionArrangement.type = distribution
            distributionArrangement.spacing = spacing
            
            // FIXME: Refresh only invalidated constraints (at least in most and perforamce-intensive common cases)
            alignmentArrangement.updateConstraints()
            distributionArrangement.updateConstraints()
        }
        super.updateConstraints()
    }
}

private class LayoutArrangement {
    weak var canvas: UIView!
    var views = [UIView]() // Arranged views
    
    var axis: UILayoutConstraintAxis = .Horizontal
    var horizontal: Bool { return axis == .Horizontal }
    var marginsEnabled: Bool = false
    
    var constraints = [NSLayoutConstraint]()
    
    init(canvas: StackView) {
        self.canvas = canvas
    }
    
    func updateConstraints() {
        canvas.removeConstraints(constraints)
        constraints.removeAll()
    }
}

private class AlignedLayoutArrangement: LayoutArrangement {
    var type: StackViewAlignment = .Fill
    
    override func updateConstraints() {
        super.updateConstraints()
        let _ = views.reduce(nil as UIView?) { previous, current in
            // Pin edges leading and trailing edges (either with .Equal : .GreaterThanOrEqual relation)
            if marginsEnabled {
                constraints.append(current.autoPinEdgeToSuperviewMargin(leadingEdge, relation: leadingRelation))
