       threads = posts[start...start+options.threads]
       log.debug "Starting at #{start}:", threads, '\n'
       # Turning the promise of an array into an array of promises
-      Q.all threads.map (post) ->
+      allDone threads.map (post) ->
         downloadFile.apply null, post
       .then -> Q.delay options.delay
       .then ->

          log.debug "Updating record #{found}", self.posts[found], 'with', array, '...\n'
          self.posts[found] = array
        return
        
      if options['refresh-db'] or (self.nbNewPosts >= 50 and self.total - start >= 50)
        process start + 50
      else

      contentLength = parseInt response.headers['content-length']
      if !options.force and (size is contentLength)
        log.notice '! Skipping', output, 'file has the same size (', size, 'bytes).\n'
        return false

      log.debug 'Remote file size:', contentLength, 'local file:', size, '\n'

      bhttp.get url, stream:true
    .then (stream) ->
      if stream
        stream.on 'progress', (completed, total) ->
          log.info 'Download progress', path.basename(file), ':', ((completed / total) * 100).toFixed(2), '%\r'
        stream.on 'error', (error) ->
          log.error 'While writing to file', error
        stream.on 'response', (response) ->
          {statusCode} = response
          log.info 'in response', statusCode, '\n'

          # A bit hacky but basically, everything not 2XX has to be retried.
          if statusCode / 100 isnt 2
            Q.reject new ApiError 'While downloading file, wrong statusCode returned', statusCode

          unless /image/.test response.headers['content-type']
            Q.reject new ApiError 'Content-Type mismatch:', response.headers['content-type']
        stream.on 'finish', ->
          if fileSize is expectedSize
            log.info "✔ #{url} (#{statusCode}) -> #{file}\n"
            Q(true)
          else
            Q.reject new ApiError 'Connection reset. Retrying.'
        stream.pipe fs.createWriteStream file

main = ->
  res = options.parse()
