         visibility     : 'visible'
         allowedDomains : ['koding.com']
 
-      _queue = [
+      async.series [
 
-        ->
+        (next) ->
           JGroup.create client, groupData, account, (err, group_) ->
-            expect(err?.message).to.not.exist
             group = group_
-            _queue.next()
+            next err
 
-        ->
+        (next) ->
           # if StackTemplate is in models, then create a StackTemplate
           # for the newly created group
-          return _queue.next()  unless 'StackTemplate' in models
+          return next()  unless 'StackTemplate' in models
           _createStackTemplate client, options, ({ stackTemplate }) ->
             query = { $set : { stackTemplates : [stackTemplate._id] } }
-            group.update query, (err) ->
-              expect(err).to.not.exist
-              _queue.next()
+            group.update query, next
 
-        -> callback { group }
-
-      ]
-
-      daisy _queue
+      ], (err) ->
+        expect(err).to.not.exist
+        callback { group }
 
 
     _createCredential = (client, options, callback) ->
       createCredential client, options, (err, data_) ->
-        expect(err?.message).to.not.exist
+        expect(err).to.not.exist
         callback data_
 
 
     _createProvisioner = (client, options, callback) ->
       createProvisioner client, options, (err, data_) ->
-        expect(err?.message).to.not.exist
+        expect(err).to.not.exist
         callback data_
 
 
     _createStackTemplate = (client, options, callback) ->
       createStackTemplate client, options, (err, data_) ->
-        expect(err?.message).to.not.exist
+        expect(err).to.not.exist
         callback data_
 
 



    _createStack = (client, options, callback) ->
      stackData = { client, user, account, template : data.stackTemplate }
      group             = null
      stackTemplate     = null
      stackTemplateData = null

      _queue = [

        ->
          # adding group to stackData, will be needed while creating stack
          JGroup.one { slug : groupSlug }, (err, group_) ->
            expect(err?.message).to.not.exist
            stackData.group = group = group_
            _queue.next()

        ->
          _createStackTemplate client, options, (data_) ->
            stackData.template = stackTemplate = data_.stackTemplate
            stackTemplateData  = data_.stackTemplateData
            _queue.next()

        ->
          # create a stack from the given template
          ComputeProvider.generateStackFromTemplate stackData, options, (err, { stack }) ->
            expect(err?.message).to.not.exist
            callback { group, stack, stackTemplate, stackTemplateData }

      ]

      daisy _queue


    _createComputeProvider = (client, options, callback) ->
      computeProvider = null
      client.r        = { group : groupSlug, user, account }
      stack           = options.stack ? null
      label           = generateRandomString()
      provider        = 'aws'
      generatedFrom   = new ObjectId

      _queue = [

        ->
          return queue.next()  if stack
          _createStack client, options, (data_) ->
            { stack } = data_
            _queue.next()

        ->
          computeProviderOptions = {
            client, stack, provider, label, generatedFrom
            users : []
            provisioners : [data.provisioner ? 'devrim/koding-base']
          }

          ComputeProvider.create client, computeProviderOptions, (err, machine) ->
            expect(err?.message).to.not.exist
            callback { machine, stack }

      ]

      daisy _queue


    models.forEach (model) ->

        when 'Provisioner'      then _createProvisioner
        when 'StackTemplate'    then _createStackTemplate
        when 'ComputeProvider'  then _createComputeProvider
        else                    -> callback 'invalid request'

      queue.push (next) ->
        fn client, options, (data_) ->
          data = _.extend data, data_
          next()

    # returning data variable after requested models created
    async.series queue, -> callback data


module.exports = {
