     opts ?= {}
     return [name, attrs, children, opts]
 
+flush = ->
+    if @buffer.length
+        @write data for data in @buffer
+        @buffer = []
+
+rmevents = (events) ->
+    @removeListener 'data', events.data
+    @removeListener event, events[event] for event in EVENTS
 
 new_tag = ->
     [name, attrs, children, opts] = parse_args arguments...
-    pipe = {}
+    events = {}
     opts.level ?= @level+1
 
     opts = deep_merge @builder.opts, opts # possibility to overwrite existing opts, like pretty

                    @buffer = @buffer.concat tag.buffer
                    tag.buffer = []
                @pending = @pending.slice(1)
                tag.removeListener 'data', pipe.data
                for event in EVENTS
                    tag.removeListener event, pipe[event]
                if @buffer.length
                    for data in @buffer
                        @write data
                    @buffer = []
                if @closed and @pending.length is 0
                    @end()
        else

                        before = @pending[i-1]
                        before.buffer = before.buffer.concat @buffer
                        @buffer = []
                    rmevents.call tag, events
                    if @closed is 'pending'
                        flush.call this
                        @end()
                    return
            throw new Error("this shouldn't happen D:")
