 
   appendPiece: (piece) ->
     if @blocks.length is 0
-      @appendBlockForAttributes({})
+      @appendEmptyBlock()
     @blocks[@blocks.length - 1].text.push(piece)
 
   appendStringToTextAtIndex: (string, index) ->

    if @isBlockElement(element) and not @isBlockElement(element.firstChild)
      attributes = getBlockAttributes(element)
      unless elementContainsNode(@currentBlockElement, element) and arraysAreEqual(attributes, @currentBlock.attributes)
        @currentBlock = @appendBlockForAttributes(attributes, element)
        @currentBlockElement = element

    else if @currentBlockElement and not elementContainsNode(@currentBlockElement, element) and not @isBlockElement(element)
        @currentBlock = @appendBlockForAttributes({})
        @currentBlockElement = null

  isExtraBR: (element) ->

          unless element.parentNode.firstChild is element
            @appendStringWithAttributes(" ")

  appendBlockForAttributesWithElement: (attributes, element) ->
    @blockElements.push(element)
    block = blockForAttributes(attributes)
    @blocks.push(block)
    block

  appendEmptyBlock: ->
    @appendBlockForAttributesWithElement({}, null)

  appendStringWithAttributes: (string, attributes) ->
    @appendPiece(pieceForString(string, attributes))

