passing synclog and scheduler as parameter to synccore
diff --git a/src/event-scheduler.cpp b/src/event-scheduler.cpp
index f4603f0..ec4b104 100644
--- a/src/event-scheduler.cpp
+++ b/src/event-scheduler.cpp
@@ -168,23 +168,24 @@
 void
 Scheduler::start()
 {
+  WriteLock lock(m_mutex);
+  if (!m_running)
   {
-    WriteLock lock(m_mutex);
+    m_thread = boost::thread(&Scheduler::eventLoop, this);
     m_running = true;
   }
-  m_thread = boost::thread(&Scheduler::eventLoop, this);
 }
 
 void
 Scheduler::shutdown()
 {
+  WriteLock lock(m_mutex);
+  if (m_running)
   {
-    WriteLock lock(m_mutex);
+    event_base_loopbreak(m_base);
+    m_thread.join();
     m_running = false;
   }
-  event_base_loopbreak(m_base);
-  cout << "shutdown, calling loop break" << endl;
-  m_thread.join();
 }
 
 bool
diff --git a/src/sync-core.cc b/src/sync-core.cc
index d90c463..8319c21 100644
--- a/src/sync-core.cc
+++ b/src/sync-core.cc
@@ -25,9 +25,9 @@
 const double SyncCore::WAIT = 0.05;
 const double SyncCore::RANDOM_PERCENT = 0.5;
 
-SyncCore::SyncCore(const string &path, const Name &userName, const Name &localPrefix, const Name &syncPrefix, const StateMsgCallback &callback, CcnxWrapperPtr handle)
-         : m_log(path, userName.toString())
-         , m_scheduler(new Scheduler())
+SyncCore::SyncCore(SyncLogPtr syncLog, const Name &userName, const Name &localPrefix, const Name &syncPrefix, const StateMsgCallback &callback, const CcnxWrapperPtr &handle, const SchedulerPtr &scheduler)
+         : m_log(syncLog)
+         , m_scheduler(scheduler)
          , m_stateMsgCallback(callback)
          , m_userName(userName)
          , m_localPrefix(localPrefix)
@@ -35,18 +35,17 @@
          , m_handle(handle)
          , m_recoverWaitGenerator(new RandomIntervalGenerator(WAIT, RANDOM_PERCENT, RandomIntervalGenerator::UP))
 {
-  m_rootHash = m_log.RememberStateInStateLog();
+  m_rootHash = m_log->RememberStateInStateLog();
   m_syncClosure = new Closure(0, boost::bind(&SyncCore::handleSyncData, this, _1, _2), boost::bind(&SyncCore::handleSyncInterestTimeout, this, _1));
   m_recoverClosure = new Closure(0, boost::bind(&SyncCore::handleRecoverData, this, _1, _2), boost::bind(&SyncCore::handleRecoverInterestTimeout, this, _1));
   m_handle->setInterestFilter(m_syncPrefix, boost::bind(&SyncCore::handleInterest, this, _1));
-  m_log.initYP(m_yp);
+  m_log->initYP(m_yp);
   m_scheduler->start();
   sendSyncInterest();
 }
 
 SyncCore::~SyncCore()
 {
-  m_scheduler->shutdown();
   if (m_syncClosure != 0)
   {
     delete m_syncClosure;
@@ -83,13 +82,13 @@
 void
 SyncCore::updateLocalState(sqlite3_int64 seqno)
 {
-  m_log.UpdateDeviceSeqNo(m_userName, seqno);
+  m_log->UpdateDeviceSeqNo(m_userName, seqno);
   // choose to update locator everytime
-  m_log.UpdateLocator(m_userName, m_localPrefix);
+  m_log->UpdateLocator(m_userName, m_localPrefix);
   HashPtr oldHash = m_rootHash;
-  m_rootHash = m_log.RememberStateInStateLog();
+  m_rootHash = m_log->RememberStateInStateLog();
 
-  SyncStateMsgPtr msg = m_log.FindStateDifferences(*oldHash, *m_rootHash);
+  SyncStateMsgPtr msg = m_log->FindStateDifferences(*oldHash, *m_rootHash);
 
   // reply sync Interest with oldHash as last component
   Name syncName = constructSyncName(oldHash);
@@ -130,10 +129,10 @@
   Bytes hashBytes = name.getComp(name.size() - 1);
   // this is the hash unkonwn to the sender of the interest
   Hash hash(head(hashBytes), hashBytes.size());
-  if (m_log.LookupSyncLog(hash) > 0)
+  if (m_log->LookupSyncLog(hash) > 0)
   {
     // we know the hash, should reply everything
-    SyncStateMsgPtr msg = m_log.FindStateDifferences(*(Hash::Origin), *m_rootHash);
+    SyncStateMsgPtr msg = m_log->FindStateDifferences(*(Hash::Origin), *m_rootHash);
     // DEBUG
     /*
     assert(msg->state_size() > 0);
@@ -180,11 +179,11 @@
     cout << "same as root hash: " << *hash << endl;
     return;
   }
-  else if (m_log.LookupSyncLog(*hash) > 0)
+  else if (m_log->LookupSyncLog(*hash) > 0)
   {
     // we know something more
     cout << "found hash in sync log" << endl;
-    SyncStateMsgPtr msg = m_log.FindStateDifferences(*hash, *m_rootHash);
+    SyncStateMsgPtr msg = m_log->FindStateDifferences(*hash, *m_rootHash);
 
     Bytes syncData;
     msgToBytes(msg, syncData);
@@ -264,13 +263,13 @@
     {
       sqlite3_int64 seqno = state.seq();
    //   cout << ", Got seq: " << seqno << endl;
-      m_log.UpdateDeviceSeqNo(deviceName, seqno);
+      m_log->UpdateDeviceSeqNo(deviceName, seqno);
       if (state.has_locator())
       {
         string locStr = state.locator();
         Name locatorName((const unsigned char *)locStr.c_str(), locStr.size());
     //    cout << ", Got loc: " << locatorName << endl;
-        m_log.UpdateLocator(deviceName, locatorName);
+        m_log->UpdateLocator(deviceName, locatorName);
         WriteLock lock(m_ypMutex);
         m_yp[deviceName] = locatorName;
       }
@@ -285,8 +284,8 @@
 
   // find the actuall difference and invoke callback on the actual difference
   HashPtr oldHash = m_rootHash;
-  m_rootHash = m_log.RememberStateInStateLog();
-  SyncStateMsgPtr diff = m_log.FindStateDifferences(*oldHash, *m_rootHash);
+  m_rootHash = m_log->RememberStateInStateLog();
+  SyncStateMsgPtr diff = m_log->FindStateDifferences(*oldHash, *m_rootHash);
 
   if (diff->state_size() > 0)
   {
@@ -305,7 +304,7 @@
 void
 SyncCore::recover(const HashPtr &hash)
 {
-  if (!(*hash == *m_rootHash) && m_log.LookupSyncLog(*hash) <= 0)
+  if (!(*hash == *m_rootHash) && m_log->LookupSyncLog(*hash) <= 0)
   {
     cout << m_userName << ", Recover for: " << *hash << endl;
     // unfortunately we still don't recognize this hash
@@ -352,5 +351,5 @@
 sqlite3_int64
 SyncCore::seq(const Name &name)
 {
-  return m_log.SeqNo(name);
+  return m_log->SeqNo(name);
 }
diff --git a/src/sync-core.h b/src/sync-core.h
index d8c9675..e94a6a9 100644
--- a/src/sync-core.h
+++ b/src/sync-core.h
@@ -46,12 +46,13 @@
   static const double RANDOM_PERCENT; // seconds;
 
 public:
-  SyncCore(const string &path                   // path where SyncLog is stored
-           , const Name &userName               // unique permanent name for local user
+  SyncCore(SyncLogPtr syncLog
+           , const Name &userName
            , const Name &localPrefix            // routable name used by the local user
            , const Name &syncPrefix             // the prefix for the sync collection
            , const StateMsgCallback &callback   // callback when state change is detected
-           , CcnxWrapperPtr handle);
+           , const CcnxWrapperPtr &handle
+           , const SchedulerPtr &scheduler);
   ~SyncCore();
 
   // some other code should call this fuction when local prefix
@@ -113,7 +114,7 @@
   msgToBytes(const SyncStateMsgPtr &msg, Bytes &bytes);
 
 protected:
-  SyncLog m_log;
+  SyncLogPtr m_log;
   SchedulerPtr m_scheduler;
   StateMsgCallback m_stateMsgCallback;
   Name m_userName;
diff --git a/src/sync-log.cc b/src/sync-log.cc
index 8375142..1e17957 100644
--- a/src/sync-log.cc
+++ b/src/sync-log.cc
@@ -116,7 +116,7 @@
               ORDER BY device_name);                               \
 ", 0,0,0);
 
-  // std::cout << sqlite3_errmsg (m_db) << std::endl;
+   std::cout << sqlite3_errmsg (m_db) << std::endl;
   if (res != SQLITE_OK)
     {
       sqlite3_exec (m_db, "ROLLBACK TRANSACTION;", 0,0,0);
diff --git a/src/sync-log.h b/src/sync-log.h
index 0a59516..aed3bce 100644
--- a/src/sync-log.h
+++ b/src/sync-log.h
@@ -95,5 +95,7 @@
   Mutex m_stateUpdateMutex;  
 };
 
+typedef boost::shared_ptr<SyncLog> SyncLogPtr;
+
 
 #endif // SYNC_LOG_H