 
       prefix = @prefix stroke, fill, clip, alpha, layerNum, layerName
 
-      if not @assSections[layerNum]?
-        @assSections[layerNum] = {}
-
-      if not @assSections[layerNum][prefix]?
-        @assSections[layerNum][prefix] = []
-
-      Array.prototype.push.apply @assSections[layerNum][prefix], ASS_createDrawingFromPoints path.pathPoints
+      layer = @layers[layerNum]
+      unless layer?
+        layer = @makeLayer()
+        @layers[layerNum] = layer
+
+      layer.addPath path, prefix
 
     prefix: (stroke, fill, clip, alpha) ->
       "{\\an7\\pos(0,0)#{stroke}#{fill}#{alpha}#{clip}\\p1}"
 
+    emptyPrefix: -> ""
     suffix: -> "{\\p0}"
 
-    get: (includeEmptyLayers = false) ->
+    get: (includeEmptyLayers) ->
       fragments = []
       suffix = @suffix()
 
-      for shapes, layerNum in @assSections
-        if shapes?
-          for prefix, paths of shapes
+      for layer in @layers when layer?
+        if includeEmptyLayers && layer.emptyPrefix?
+            fragments.push layer.emptyPrefix
+            fragments.push "\n"
+
+        for mergeGroup in layer.groups
+          for prefix, drawing of mergeGroup.lines
             fragments.push prefix
-            fragments.push paths.join " "
+            fragments.push drawing.join " "
             fragments.push suffix
-            fragments.push "\n"
-        else if includeEmptyLayers
             fragments.push "\n"
 
       fragments.pop()

      output.prefix = (stroke, fill, clip, alpha, layerNum, layerName) ->
        "Dialogue: #{layerNum},0:00:00.00,0:00:00.00,AI,#{layerName},0,0,0,,{\\an7\\pos(0,0)#{stroke}#{fill}#{alpha}#{clip}\\p1}"
      output.suffix = -> ""


  alert "Your colorspace needs to be RGB if you want colors." if doc.documentColorSpace == DocumentColorSpace.CMYK

                clip = makeClip clipPath
              @processedPathCnt += 1

            for subPageItem in obj.pageItems by -1 when not subPageItem.clipping
              @process subPageItem, clip, opacity

          when "PathItem"
