   cb null, type: resolvedType.name  # returning repr right away
 
 
+# *Element* handler factory.
+createElementHandler = (resolvedType) ->
+  switch resolvedType.name
+    when 'object'
+      handleObjectElement
+    when 'array'
+      handleArrayElement
+    when 'enum'
+      handleEnumElement
+    else
+      handlePrimitiveElement
+
+
 # Generates JSON Schema representation for given *Element* node.
 handleElement = (element, inherited, cb) ->
-  resolveType element, inherited.typeName, (err, resolvedType) ->
-    return cb err if err
-
-    switch resolvedType.name
-      when 'object'
-        handleObjectElement element, resolvedType, inherited, cb
-      when 'array'
-        handleArrayElement element, resolvedType, inherited, cb
-      else
-        handlePrimitiveElement element, resolvedType, inherited, cb
+  async.waterfall [
+    (next) -> resolveType element, inherited.typeName, next
+    (resolvedType, next) ->
+      handle = createElementHandler resolvedType
+      handle element, resolvedType, inherited, next
+  ], cb
 
 
 # Adds JSON Schema declaration to given representation object.

  nestedTypeName = resolvedType.nested[0]

  vals = inspect.listValues arrayElement
  async.map vals, (val, next) ->
    buildValueRepr val, nestedTypeName, next
  , cb


# Takes 'resolved items' and generates JSON Schema for their wrapper array
# *Element* node. This function chooses strategy and delegates to other
# helper functions.
buildArrayItemsRepr = ({arrayElement, resolvedItems, resolvedType, fixed}, cb) ->
  if fixed
    buildTupleItemsRepr arrayElement, resolvedItems, resolvedType, cb
  else if (ri for ri in resolvedItems when ri.fixed).length  # if contains fixed
