      reader.readAsDataURL file
 
    loadDirEntry: (entry, callback) ->
-    return unless entry.isDirectory
-    console.log entry.fullPath
-    reader = entry.createReader()
-    self = this
-    dirs = []
-
-    readEntries = ->
-     reader.readEntries onRead, self.on.error
-
-    onRead = (results) ->
-     if results.length is 0
-      for e in dirs
-       self.loadDirEntry e
-      dirs = []
-      return
-
-     for e in results
-      if e.isDirectory
-       dirs.push e
-      else
-       self.addResource e
+    dirs = [entry]
+    n = 0
+
+    readEntries = =>
+     while true
+      if n >= dirs.length
+       return callback
+      entry = dirs[n]
+      ++n
+      break if entry? and entry.isDirectory
+
+     console.log entry.fullPath
+     reader = entry.createReader()
+     reader.readEntries =>
+      for e in results
+       if e.isDirectory
+        dirs.push e
+       else
+        self.addResource e
       readEntries()
+     , @on.error
 
     readEntries()
 


    setTimeout reentrant, 100

   @listen 'openDirectory', (entry) ->
    return unless entry?

    chrome.storage.local.set
     directory: chrome.fileSystem.retainEntry entry

    @loadDirEntry entry

   @listen 'file', (e) ->
    chrome.fileSystem.chooseEntry

         setTimeout =>
          @loadSavedContent =>
           @_loading = false
          , 0
        , 0
       , 0

   loadRetainedDirectory: (callback) ->
    chrome.storage.local.get 'directory', (directory) =>
     directory = directory?.directory
     return callback() if not directory?
     chrome.fileSystem.isRestorable directory, (isRestorable) =>
      return callback() if not isRestorable
      chrome.fileSystem.restoreEntry directory, (d) =>
       @on.openDirectory d, callback

   loadRetainedFile: (callback) ->
    chrome.storage.local.get 'file', (file) =>
     file = file?.file
     return callback if not file?
     chrome.fileSystem.isRestorable file, (isRestorable) =>
      return callback() if not isRestorable
      chrome.fileSystem.restoreEntry file, (d) =>
       @on.openFile d, callback

   saveContent: (value, callback) ->
    return if @_loading
