 // Retrieve a specific StylePropertySet by name or by type
 extension StyleClass {
     mutating func register(propertySet:StylePropertySet) {
-        stylePropertySets.register(propertySet)
+        if isKnownUniquelyReferenced(&stylePropertySets) {
+            stylePropertySets.register(propertySet: propertySet)
+        } else {
+            stylePropertySets = StylePropertySetCollection(asCopyOf: stylePropertySets)
+            stylePropertySets.register(propertySet: propertySet)
+        }
     }
     func retrieve<T:StylePropertySet>(propertySet:T.Type)->T {
-        return stylePropertySets.retrieve(propertySet)
+        return stylePropertySets.retrieve(propertySetType: propertySet)
     }
     func retrieve(dynamicPropertySetName:String)->DynamicStylePropertySet? {
-        return stylePropertySets.retrieve(dynamicPropertySetName)
+        return stylePropertySets.retrieve(dynamicPropertySetName: dynamicPropertySetName)
     }
 }
 

    var alpha: CGFloat?
    var layoutMargins:UIEdgeInsets?
    var tintColor:UIColor?
    var customUIViewStyleBlock:(UIView->())?
    mutating func setStyleProperty<T>(named name: String, toValue value: T) {
        switch name {
        case _ where name.isVariantOf("Background Color"):
            backgroundColor = value as? UIColor
        case _ where name.isVariantOf("Content Mode"):
            contentMode = value as? UIViewContentMode
        case _ where name.isVariantOf("User Interaction Enabled"):
            userInteractionEnabled = value as? Bool
        case _ where name.isVariantOf("Hidden"):
            hidden = value as? Bool
        case _ where name.isVariantOf("Border Color"):
            borderColor = (value as! CGColor)
        case _ where name.isVariantOf("Border Width"):
            borderWidth = value as? CGFloat
        case _ where name.isVariantOf("Corner Radius"):
            cornerRadius = value as? CGFloat
        case _ where name.isVariantOf("Corner Radius Percentage"):
            cornerRadiusPercentage = value as? CGFloat
        case _ where name.isVariantOf("Alpha"):
            alpha = value as? CGFloat
        case _ where name.isVariantOf("Layout Margins"):
            layoutMargins = value as? UIEdgeInsets
        case _ where name.isVariantOf("Tint Color"):
            tintColor = value as? UIColor
        case _ where name.isVariantOf("Masks To Bounds"):
            masksToBounds = value as? Bool
        case _ where name.isVariantOf("Clips To Bounds"):
            clipsToBounds = value as? Bool
        default :
            return

    }
    
    private func useCachedJSON(forStylesheetType:Stylesheet.Type) -> Bool {
        let jsonCacheDuration = 3.0
        let isJSON = forStylesheetType is JSONStylesheet.Type
        let cacheExists = JSONStylesheet.cachedStylesheet != nil
        let isCacheExpired = NSDate.timeIntervalSinceReferenceDate - JSONStylesheet.cacheTimestamp > jsonCacheDuration
        return isJSON && cacheExists && !isCacheExpired
    }
    
    func showErrorIfInvalidStyles() {
        showErrorIfInvalid(styles: styles, usingStylesheet: stylesheet)
    }
    
    func showErrorIfInvalid(styles:String, usingStylesheet stylesheetName:String) {
        let components = styles.replacingOccurrences(of:", ", with: ",").replacingOccurrences(of:" ,", with: ",").components(separatedBy:",")
        
        var invalidStyle = false
        for subview in subviews {
