     buildFsTree devicename, { filePath: filePath }, (err, res) ->
 
         # Fetch only files
-        db.db.query { map: (doc) ->
-
-            if doc.docType is 'File'
-                emit doc._id, doc
-
-        }, (err, res) ->
-            for doc in res.rows
+        db.db.query { map: (doc) -> emit doc._id, doc if doc.docType is 'File' }, (err, res) ->
+            async.each res.rows, (doc, callback) ->
                 doc = doc.value
-                if not filePath? or filePath is path.join doc.path, doc.name
-                    filePath = path.join remoteConfig.path, doc.path, doc.name
-                    if doc.binary?
-                        binaryUri = "cozy/#{doc.binary.file.id}/file"
-                        # Fetch binary via CouchDB API
-                        client.saveFile binaryUri, filePath, (err, res, body) ->
-                            if err
-                                console.log err
-
-                            # Rebuild FS Tree to correct utime
-                            buildFsTree devicename, { filePath: path.join doc.path, doc.name }, callback
+                if (not filePath? or filePath is path.join doc.path, doc.name) and doc.binary?
+                    binaryPath = path.join remoteConfig.path, doc.path, doc.name
+                    binaryUri = "cozy/#{doc.binary.file.id}/file"
+                    # Fetch binary via CouchDB API
+                    client.saveFile binaryUri, binaryPath, (err, res, body) ->
+                        console.log err if err
+
+                        # Rebuild FS Tree to correct utime
+                        buildFsTree devicename, { filePath: path.join doc.path, doc.name }, callback
+                else
+                    callback()
+            , callback
 
 
 putDirectory = (devicename, directoryPath, recursive, callback) ->

    dirLastModification = stats.mtime

    # Lookup for existing directory
    db.db.query { map: (doc) ->

        if doc.docType is 'Folder'
            emit doc._id, doc

    }, (err, res) ->
        for doc in res.rows
            doc = doc.value
            if doc.path is dirPath and doc.name is dirName

            emit doc._id, doc

    }, (err, res) ->
        async.each res.rows, (doc, callback) ->
            doc = doc.value
            if not filePath? or filePath is path.join doc.path, doc.name
                name = path.join remoteConfig.path, doc.path, doc.name
                if doc.docType is 'Folder'
                    # Create folder
                    mkdirp name, () ->
                        fs.utimes name,
                            new Date(doc.creationDate),
                            new Date(doc.lastModification),
                            () ->
                                callback()
                else
                    # Create parent folder and touch file
                    mkdirp path.join(remoteConfig.path, doc.path), () ->
                        touch name, () ->
                            fs.utimes name,
                                new Date(doc.creationDate),
                                new Date(doc.lastModification),
                                () ->
                                    callback()
        , callback


fetchBinaries = (devicename, options, callback) ->
