                             # Remove access information
                             # from application/device document
                             db.save app, (err, doc) ->
-                                log.error 'ERROR 3' if err?
                                 log.error err if err?
                                 cb()
                     else


    # Add access for all applications and devices
    addAccess 'application', (err) ->
        log.error 'ERROR 4' if err?
        log.error err if err?
        addAccess 'device', (err) ->
            log.error 'ERROR 5' if err?
            log.error err if err?
            callback()


            return cb(err) if err? or apps.length is 0
            async.forEachSeries apps, (app, cb) ->
                # Check if access exists
                db.view 'access/byApp', key:app.id, (err, accesses) ->
                    return cb(err) if err? or accesses.length is 0
                    if accesses?.length is 0
                        # Create it if necessary
