         when ' '
           # nested element with tag-name
           queryTokens.unshift token[2]
-          innerContents = $.egen(queryTokens, null, innerContents)
-          queryTokens = []
-          continue
+          element.appendChild $.egen(queryTokens, null, innerContents, 1)
+          innerContents = 0
         else
           throw "The query token provided ('#{tokenStr}') is not a valid token type."
-
-    # set attributes
-    $element.attr attrs if attrs
 
     # set inner contents
     if innerContents
       if typeof innerContents is 'string'
         # disable html code
-        $element.text(innerContents)
+        element.appendChild document.createTextNode(innerContents)
       else
+        $element = $(element) if raw
         $element.append(innerContents)
 
-    $element
+    if raw
+      element
+    else
+      $element
 
   $.fn.egen = $.fn.eGen = (queryTokens, attrs, innerContents) ->
     @append $.egen(queryTokens, attrs, innerContents)

    else
      if typeof queryTokens is 'string'
        queryTokens = queryTokens.split /(?![\w\-]+|$)/
      else
        queryTokens = queryTokens.concat() # duplicate
      if queryTokens[0] and /^\w/.test queryTokens[0]
        tagName = queryTokens.shift()
      else
        tagName = 'div'
    element = document.createElement tagName
    $element = $(element)

    # setup id, class
    while queryTokens.length


  document = window.document

  $.egen = $.eGen = (queryTokens, attrs, innerContents, raw) ->
    tagName = id = null

    # generate element
