     return """<#{tag}#{_renderAttr(attributes)}>#{_renderChildren(children)}</#{tag}>"""
 
   $.append = (parent,child) ->
+    parent.children = [] if !parent.children?
     parent.children.push child
 
   $.prepend = (parent,child) ->
+    parent.children = [] if !parent.children?
     parent.children.splice 0, 0, child
 
-  $.mergeattributes = (attributes1,attributes2) ->
+  $.mergeattributes = (attributes1={},attributes2={}) ->
     # merge shared key values where value is same type, preferring attributes1, otherwise fallback to attributes2
     attributes = {}
     for key, val of attributes1


  _renderAttr = (o) ->
    attributes = ''
    for key, val of o
      continue unless notAttr.indexOf(key) is -1
      if key is 'style'

        else if (typeof v1 is 'string') and (typeof v2 is 'string')
          attributes[key] += v1 + " " + v2
        else if (typeof v1 is 'object') and (typeof v2 is 'object')
          # TODO: not clone
          # clone to not disrupt $h!t up the closures
          v2 = JSON.parse JSON.stringify v2
          # prefer styles from attributes1
