   .then (outputDir) =>
     logger.debug "Created output dir at #{outputDir}"
     @outputDir = outputDir
+
+    # fetch all orders
     client.orders.all()
     .expand('lineItems[*].state[*].state')
     .expand('lineItems[*].supplyChannel')

        logger.error err, "Problems on getting sftp credentials from config files for project #{argv.projectKey}."
        @exitCode = 1
    else
      Promise.resolve()
  .then =>
    logger.info 'Orders export complete'
    @exitCode = 0

    orderExport.processOrders(result.body.results, argv.csvTemplate)
  .then (result) =>
    @orderReferences = []
    ts = (new Date()).getTime()
    if isCsvMode()
      if argv.fileWithTimestamp
        fileName = "orders_#{ts}.csv"
      else
        fileName = 'orders.csv'
      csvFile = argv.csvFile or "#{@outputDir}/#{fileName}"
      logger.info "Storing CSV export to '#{csvFile}'."
      fs.writeFileAsync csvFile, result
    else
      logger.info "Storing #{_.size result} file(s) to '#{@outputDir}'."
      Promise.map result, (entry) =>
        content = entry.xml.end(pretty: true, indent: '  ', newline: '\n')
        if argv.fileWithTimestamp
          fileName = "#{entry.id}_#{ts}.xml"
        else
          fileName = "#{entry.id}.xml"
        @orderReferences.push name: fileName, entry: entry
        fs.writeFileAsync "#{@outputDir}/#{fileName}", content
      , {concurrency: 10}
