 
     fileprivate func prepareSvg(_ node: XMLIndexer) throws {
         if let element = node.element {
-            if element.name == "defs" {
-                try parseDefinitions(node)
-            } else if element.name == "style" {
+            if element.name == "style" {
                 parseStyle(node)
-            } else if element.name == "g" {
+            } else if (element.name == "defs" || element.name == "g") {
                 try node.children.forEach { child in
                     try prepareSvg(child)
+                }
+            }
+            if let id = element.allAttributes["id"]?.text {
+                switch element.name {
+                case "linearGradient", "radialGradient", "fill":
+                    defFills[id] = parseFill(node)
+                case "mask":
+                    defMasks[id] = try parseMask(node)
+                case "filter":
+                    defEffects[id] = try parseEffect(node)
+                case "clip":
+                    defClip[id] = try parseClip(node)
+                default:
+                    defNodes[id] = node
                 }
             }
         }

                             stroke: getStroke(style, groupStyle: style), opacity: getOpacity(style), fontName: getFontName(style), fontSize: getFontSize(style), fontWeight: getFontWeight(style), pos: position)
        case "use":
            return try parseUse(node, groupStyle: style, place: position)
        case "linearGradient", "radialGradient", "fill":
            if let fill = parseFill(node), let id = id {
                defFills[id] = fill
            }
        case "filter":
            if let effect = try parseEffect(node), let id = id {
                defEffects[id] = effect
            }
        case "mask":
            if let mask = try parseMask(node), let id = id {
                defMasks[id] = mask
            }
        case "title":
            break
        default:

            switch element.name {
            case "g":
                result = try parseGroup(node, style: style)
            case "style", "defs":
                // do nothing - it was parsed on first iteration
                return .none
