             err = new Error "The doc is invalid: #{JSON.stringify doc}"
             callback err
 
-        unless doc.path?.indexOf('undefined') < 0
+        else if doc.path?.indexOf('undefined') < 0
             pouch.db.remove doc, (err) ->
                 err = new Error "The doc was invalid: #{JSON.stringify doc}"
                 callback err

            ]

            if task.operation in replicationDelayingOperations
                    delay = 1000
                    pouch.replicationDelay += delay
                    setTimeout ->
                        pouch.replicationDelay -= delay

                    operationQueue.createFolderLocally doc, done
            , callback

    #
    # Local-to-remote operations
    #
