     relative = []
     libraryManager.pathsCommonPrefix files, relative, basePath
     map = {}
-    for i in [0..files.length]
+    for i in [0..files.length-1]
       map[relative[i]] = files[i]
     return map
 
   # Compile current project in the cloud
+  # when updating arguments here, also update the event emitter above
   compileCloud: (thenFlash=null, files=null, rootPath=null) -> @loginRequired =>
     if !@canCompileNow
       return

          @SettingsHelper.setLocal 'compile-status', {filename: filename}
          atom.commands.dispatch @workspaceElement, "#{@packageName()}:update-compile-status"
          if !!thenFlash
            setTimeout =>
              atom.commands.dispatch @workspaceElement, "#{@packageName()}:flash-cloud"
              @downloadBinaryPromise = null
            , 500
          else
            @downloadBinaryPromise = null
        , (e) =>

    @compileErrorsView.show()

  # Flash core via the cloud
  flashCloud: (firmware=null) -> @deviceRequired =>
    fs ?= require 'fs-plus'
    path ?= require 'path'
    _s ?= require 'underscore.string'
    utilities ?= require './vendor/utilities'
    console.log 'flashCloud', firmware

    currentPlatform = @getCurrentPlatform()

    files = null
    rootPath = null
    if firmware
      files = [firmware]
    else
      @projectRequired =>
        rootPath = @getProjectDir()
        files = fs.listSync(rootPath)
        files = files.filter (file) ->
          return (utilities.getFilenameExt(file).toLowerCase() == '.bin') &&
                 (_s.startsWith(path.basename(file), currentPlatform))

    if files.length is 0
      # If no firmware file, compile
      @emitter.emit "#{@packageName()}:compile-cloud", {thenFlash: true}
    else if (files.length == 1)
      # If one firmware file, flash
      firmware = files[0]
      flashDevice = =>
        if !!rootPath
          process.chdir rootPath
          firmware = path.relative rootPath, firmware

        @statusView.setStatus 'Flashing via the cloud...'

