         client = request.newClient options.url
         client.setBasicAuth 'owner', options.password
 
-        finish =  (res, body) ->
-            callback null
-
-        onError =  (err) ->
-            log.error err.toString()
-            console.error err
-            callback err
-
         client.delAsync("device/#{options.deviceId}/")
-        .then finish
-        .catch onError
+        .nodeify callback
 
 
     # Specify which way to replicate


        data = login: options.deviceName

        getCredentials = (res) ->
            if res[0].body.error
                callback res[0].body.error
            else
                body = res[0].body
                callback null,
                    id: body.id
                    password: body.password

        onError =  (err) ->
            log.error err.toString()
            console.error err
            callback err

        client.postAsync('device/', data)
            .then getCredentials
            .catch onError


    # Unregister device remotely, ask for revocation.

            # Lock file watcher to avoid remotely downloaded files to be re-uploaded
            filesystem.watchingLocked = true

            unlockFileSystemAndReturn = ->
                filesystem.watchingLocked = false
                callback null

