     )
 
   _populateGrammars: (grammarsFromJSON,grammarsArray,cb) ->
-    toLoad = grammarsArray.length
+    toLoad = (grammarsArray||[]).length
     grammars = []
 
     done = (err,grammar)=>
       if err
         return cb(err)
 
-      grammars.push(grammar)
+      if grammar
+        grammars.push(grammar)
 
       if !--toLoad
         # complete loading from grammars.json


        cb(false,true)
   
    while grammarsArray.length
      @registry.loadGrammar(grammarsArray.shift(),done)


      if !--todo
        cb()

    fs.readdir(dir, (err, files)=>
      if err
        return cb(err)
      todo = files.length

      while files.length
        file = files.shift()
        grammarPath = path.join(dir, file)
        # CSON.resolve uses fs.isFileSync we'll have to check it in the next step but only on valid files.
        if CSON.isObjectPath(grammarPath)
          @_registryLoadGrammar(grammarPath,(err)->
            done(err)
          )
    )

  _registryLoadGrammar:(grammarPath,cb)->
    fs.stat(grammarPath,(err,stat)=>
      if err
        return cb(err)

