         queue[name] = defines
         return undefined
 
+    # Execute factory function and store it in cache
     cache[name] = define.apply context, cacheDeps
 
     # Check queue
-    if Object.keys(queue).length > 0
-      for own key, value of queue
-        module key, value
+    queueList = Object.keys(queue)
 
-      delete queue[key]
+    for q in queueList
+      # Have all required dependencies been loaded?
+      maxDeps = queue[q].require.length
+      curDeps = 0
+
+      (curDeps++ if cache[d]) for d in queue[q].require
+
+      # Reload module and delete item from queue
+      if curDeps is maxDeps
+        modName = q
+        modDefinition = queue[q]
+        delete queue[q]
+        moloFunc modName, modDefinition
 
     null
 

  queue = {}

  moloFunc = (name, defines) ->
    return undefined unless name and defines

    if typeof defines is 'function' then define = defines else {define, require: deps, context} = defines

    deps = [] unless deps?
    context = @ unless context?

    if typeof deps is 'string' then deps = [deps]
    cacheDeps = []
    for i in deps
      if cache[i]


  root.molo = moloFunc
  root.molo.config = moloConfig
  root.molo.clear = ->
    cache = {}
    queue = {}

  root.molo.delete = (name) ->
    delete cache[name] if cache[name]
    delete queue[name] if queue[name]

  # Overwrite module only if it hasn't been defined
  root.module or= moloFunc

  # Compability to official definition
  root.define = (name, deps, defines) -> 
    moloFunc name, 
      require: deps, 
      define: defines

  root.define.amd =
    jQuery: true