             tags: []
 
         db.put document, newId, (err, res) ->
-            if recursive
-                putSubFiles callback
+            if args.recursive?
+                return putSubFiles callback
             else
-                callback err, res
+                return callback err, res
 
     putSubFiles = (callback) ->
         # List files in directory

          console.log info
      .on 'complete', (info) ->
          log.info 'Replication is complete'
      .on 'error', (err) ->
          log.error err


    absolutePath = path.resolve directoryPath
    relativePath = absolutePath.replace remoteConfig.path, ''
    if relativePath is absolutePath
        log.error "Directory is not located on the synchronized directory: #{absolutePath}"
        return callback()
    if relativePath.split('/').length > 2
        dirPath = relativePath.replace "/#{dirName}", ''
