 	catch
 		errors.handle(new Error("Invalid project: #{directory}"))
 
-plugins.register 'resin-plugin-*', (error, loadedPlugins) ->
+async.waterfall([
 
-	errors.handle(error) if error?
+	(callback) ->
+		plugins.register('resin-plugin-*', callback)
 
-	cli = capitano.parse(process.argv)
+	(loadedPlugins, callback) ->
+		dataPrefix = resin.settings.get('dataPrefix')
+		resin.data.prefix.set(dataPrefix, callback)
 
-	resin.data.prefix.set resin.settings.get('dataPrefix'), (error) ->
-		errors.handle(error) if error?
+	(callback) ->
+		cli = capitano.parse(process.argv)
 
 		if cli.global.quiet
 			console.info = _.noop

_ = require('lodash')
path = require('path')
capitano = require('capitano')
resin = require('resin-sdk')
nplugm = require('nplugm')
actions = require('./actions')
errors = require('./errors')
plugins = require('./plugins')

		if cli.global.project?
			changeProjectDirectory(cli.global.project)

		capitano.execute(cli, callback)

], errors.handle)
