}, function (err, result) {
   if (err) {
     debug(new Date() + "unable to replicate the map reduces to the new user's database " + dbConnection.dbname, err);
   }
   c.replicate({
     source: 'new_lexicon',
     target: dbConnection.dbname
   }, function (err, result) {
     debug(new Date() + "replicated the lexicon for the new user's database " + dbConnection.dbname, result);
   });
   // c.replicate({
   //   "source": 'new_export',
   //   "target": dbConnection.dbname
   // }, function(err, result) {
   //   debug(new Date() + "replicated the export for the new user's database "+ dbConnection.dbname, result);
   // });
   /*
    * Prepare corpus activity feed couch
    */
   createDBforCorpusTeamsActivities(dbConnection, user, function (couchdbresponse) {
     debug(new Date() + " There was success in creating the corpus team's activity feed: " + couchdbresponse);
     if (typeof success === 'function') {
       dbConnection.dbname.replace('-activity_feed', '');
       success(dbConnection);
     }
   }, function (err) {
     debug(new Date() + " There was an error in creating the corpus team's activity feed: " + err);
     if (typeof error === 'function') {
       error(dbConnection);
     }
   });
 }); // end create activity feeds
 db.create(function createHandler(err, couchdbresponse) {
   debug(new Date() + ' In the callback of db create for ' + dbConnection.dbname, couchdbresponse);
   if (err !== null) {
     debug(new Date() + ' Here are the errors ' + util.inspect(err));
   } else {
     debug(new Date() + ' corpus created');
   }
   /*
    * Upon success of db creation, set up the collaborator, contributor
    * and admin roles for this corpus teams activity feed, at the
    * moment its readers are the same as the corpus itself, and its
    * admins are only the app.
    *
    * References: http://127.0.0.1:5984/john7corpus/_security
    */
   var securityParamsforNewDB = {
     admins: {
       names: [],
       roles: ['fielddbadmin']
     },
     members: {
       names: [],
       roles: [
         dbConnection.dbname.replace('-activity_feed', '') + '_' + collaborator,
         dbConnection.dbname.replace('-activity_feed', '') + '_' + contributor,
         dbConnection.dbname.replace('-activity_feed', '') + '_' + commenter
       ]
     }
   };
   db.save('_security', securityParamsforNewDB, function (err, doc) {
     if (doc === undefined) {
       doc = {
         error: err
       };
     }
     if (err !== null || !doc.ok) {
       debug(new Date() + ' Here are the errors ' + util.inspect(err) + ' \n Here is the doc we get back ' + util.inspect(doc));
     } else {
       debug(new Date() + ' TeamsActivities _security created');
     }
   });
   /*
    * Replicate the validation design docs and the couch app to the new
    * activity feed
    */
   c.replicate({
     source: 'new_corpus_activity_feed',
     target: dbConnection.dbname
   }, function () {
     if (typeof successcallback === 'function') {
       successcallback();
     }
   }); // end replicate defaults
 }); // end createdb
 db.create(function createHandler(err, couchdbresponse) {
   debug(new Date() + ' In the callback of db create for ' + dbConnection.dbname, couchdbresponse);
   if (err) {
     debug(new Date() + ' Here is the err: ' + err);
   }
   /*
    * Upon success of db creation, set up the collaborator, contributor and
    * admin roles for this corpus
    *
    * Admins: Only the app is the admin Members: Only the user is a member
    *
    * References: http://127.0.0.1:5984/john7corpus/_security
    */
   var securityParamsforNewDB = {
     admins: {
       names: [],
       roles: ['fielddbadmin']
     },
     members: {
       names: [user.username],
       roles: []
     }
   };
   db.save('_security', securityParamsforNewDB, function (err, doc) {
     if (doc === undefined) {
       doc = {
         error: err
       };
     }
     if (err !== null || !doc.ok) {
       debug(new Date() + ' Here are the errors ' + util.inspect(err) + ' \n Here is the doc we get back ' + util.inspect(doc));
     } else {
       debug(new Date() + ' UserActivity _security created');
     }
   });
   /*
    * Replicate the validation design docs and the couch app to the new
    * activity feed
    */
   c.replicate({
     source: 'new_user_activity_feed',
     target: dbConnection.dbname
   }, function () {
     if (typeof successcallback === 'function') {
       successcallback();
     }
   }); // end replicate defaults
 }); // end createdb
 db.create(function createHandler(err, couchdbresponse) {
   debug(new Date() + ' In the callback of db create for ' + dbConnection.dbname, couchdbresponse);
   if (err) {
     debug(new Date() + ' Here is the err: ' + err);
   }
   /*
    * Upon success of db creation, set up the collaborator,
    * contributor and admin roles for this corpus
    *
    * Admins: The admins can perform any operation on the corpus.
    * Members: By adding items to the members the corpus becomes
    * non-public in the sense of couch not allowing access. We can
    * still use FieldDB to perform a fine grained control by
    * creating a special public user which is essentially the
    * checkbox that the user can check to make the corpus private,
    * and adding all fielddbusers to a role fielddbusers which can
    * let the user make the corpus private to the world, but
    * viewable by fielddbusers (to let only signed in users comment
    * on their data etc)
    *
    * If public corpus (by default its private): -signed in
    * fielddbusers can read other user's corpora until the user
    * takes that role off -public user (ie the general public) can
    * see the user's corpora through fielddb, but not directly the
    * couch database. This is how the public checkbox is
    * implemented in fielddb.
    *
    * References: http://127.0.0.1:5984/john7corpus/_security
    */
   addRoleToUser(dbConnection, {
     username: user.username,
     add: [
       dbConnection.dbname + '_' + admin,
       dbConnection.dbname + '_' + contributor,
       dbConnection.dbname + '_' + collaborator,
       dbConnection.dbname + '_' + commenter
     ]
   });
   var securityParamsforNewDB = {
     admins: {
       names: [],
       roles: ['fielddbadmin', dbConnection.dbname + '_' + admin]
     },
     members: {
       names: [],
       roles: [dbConnection.dbname + '_' + collaborator,
         dbConnection.dbname + '_' + contributor
       ]
     }
   };
   db.save('_security', securityParamsforNewDB,
     function (err, doc) {
       if (doc === undefined) {
         doc = {
           error: err
         };
       }
       if (err !== null || !doc.ok) {
         debug(new Date() + ' Here are the errors ' + util.inspect(err) + ' \n Here is the doc we get back ' + util.inspect(doc));
       } else {
         debug(new Date() + ' Corpus _security created');
       }
     });
   /*
    * Copy all design docs and the couchapp to the new user's
    * database
    */
   var sourceDB = 'new_corpus';
   if (user.whichUserGroup && user.whichUserGroup == 'betatesters') {
     sourceDB = 'new_testing_corpus';
   }
   c.replicate({
     source: sourceDB,
     target: dbConnection.dbname
   }, function (err, result) {
     if (err) {
       debug(new Date() + "unable to replicate the map reduces to the new user's database " + dbConnection.dbname, err);
     }
     c.replicate({
       source: 'new_lexicon',
       target: dbConnection.dbname
     }, function (err, result) {
       debug(new Date() + "replicated the lexicon for the new user's database " + dbConnection.dbname, result);
     });
     // c.replicate({
     //   "source": 'new_export',
     //   "target": dbConnection.dbname
     // }, function(err, result) {
     //   debug(new Date() + "replicated the export for the new user's database "+ dbConnection.dbname, result);
     // });
     /*
      * Prepare corpus activity feed couch
      */
     createDBforCorpusTeamsActivities(dbConnection, user, function (couchdbresponse) {
       debug(new Date() + " There was success in creating the corpus team's activity feed: " + couchdbresponse);
       if (typeof success === 'function') {
         dbConnection.dbname.replace('-activity_feed', '');
         success(dbConnection);
       }
     }, function (err) {
       debug(new Date() + " There was an error in creating the corpus team's activity feed: " + err);
       if (typeof error === 'function') {
         error(dbConnection);
       }
     });
   }); // end create activity feeds
 }); // end replicate defaults