Checkpoint
diff --git a/model/sync-app-data-fetch.cc b/ccnx/sync-app-data-fetch.cc
similarity index 100%
rename from model/sync-app-data-fetch.cc
rename to ccnx/sync-app-data-fetch.cc
diff --git a/model/sync-app-data-fetch.h b/ccnx/sync-app-data-fetch.h
similarity index 100%
rename from model/sync-app-data-fetch.h
rename to ccnx/sync-app-data-fetch.h
diff --git a/model/sync-app-data-publish.cc b/ccnx/sync-app-data-publish.cc
similarity index 100%
rename from model/sync-app-data-publish.cc
rename to ccnx/sync-app-data-publish.cc
diff --git a/model/sync-app-data-publish.h b/ccnx/sync-app-data-publish.h
similarity index 100%
rename from model/sync-app-data-publish.h
rename to ccnx/sync-app-data-publish.h
diff --git a/model/sync-app-socket-c.cc b/ccnx/sync-app-socket-c.cc
similarity index 100%
rename from model/sync-app-socket-c.cc
rename to ccnx/sync-app-socket-c.cc
diff --git a/model/sync-app-socket-c.h b/ccnx/sync-app-socket-c.h
similarity index 100%
rename from model/sync-app-socket-c.h
rename to ccnx/sync-app-socket-c.h
diff --git a/model/sync-app-socket.cc b/ccnx/sync-app-socket.cc
similarity index 100%
rename from model/sync-app-socket.cc
rename to ccnx/sync-app-socket.cc
diff --git a/model/sync-app-socket.h b/ccnx/sync-app-socket.h
similarity index 100%
rename from model/sync-app-socket.h
rename to ccnx/sync-app-socket.h
diff --git a/model/sync-logic-event-container.h b/ccnx/sync-logic-event-container.h
similarity index 97%
rename from model/sync-logic-event-container.h
rename to ccnx/sync-logic-event-container.h
index 65c8ab2..ebab72a 100644
--- a/model/sync-logic-event-container.h
+++ b/ccnx/sync-logic-event-container.h
@@ -23,6 +23,8 @@
 #ifndef SYNC_LOGIC_EVENT_CONTAINER_H
 #define SYNC_LOGIC_EVENT_CONTAINER_H
 
+#include "sync-event.h"
+
 #include <boost/function.hpp>
 #include <boost/date_time/posix_time/posix_time_types.hpp>
 
@@ -40,8 +42,6 @@
 namespace Sync
 {
 
-typedef boost::function< void ( ) > Event;
-
 struct LogicEvent
 {
   LogicEvent (const boost::system_time &_time, Event _event, uint32_t _label)
diff --git a/ccnx/sync-scheduler.cc b/ccnx/sync-scheduler.cc
index 4f9e082..4ec13de 100644
--- a/ccnx/sync-scheduler.cc
+++ b/ccnx/sync-scheduler.cc
@@ -107,23 +107,15 @@
   // cout << "Exited...\n";  
 }
 
-
-void
-Scheduler::schedule (const boost::system_time &abstime, Event event, uint32_t label)
-{
-  {
-    lock_guard<mutex> lock (m_eventsMutex);
-    m_events.insert (LogicEvent (abstime, event, label));
-  }
-  m_eventsCondition.notify_one ();
-  m_thread.interrupt (); // interrupt sleep, if currently sleeping
-}
-
 void
 Scheduler::schedule (const boost::posix_time::time_duration &reltime, Event event, uint32_t label)
 {
-  // cout << reltime << endl;
-  schedule (boost::get_system_time () + reltime, event, label);
+  {
+    lock_guard<mutex> lock (m_eventsMutex);
+    m_events.insert (LogicEvent (boost::get_system_time () + reltime, event, label));
+  }
+  m_eventsCondition.notify_one ();
+  m_thread.interrupt (); // interrupt sleep, if currently sleeping
 }
 
 void
diff --git a/ccnx/sync-scheduler.h b/ccnx/sync-scheduler.h
index 10ef210..53b40af 100644
--- a/ccnx/sync-scheduler.h
+++ b/ccnx/sync-scheduler.h
@@ -49,15 +49,6 @@
   ~Scheduler ();
 
   /**
-   * @brief Schedule an event at absolute time 'abstime'
-   * @param abstime Absolute time
-   * @param event function to be called at the time
-   * @param label Label for the event
-   */
-  void
-  schedule (const boost::system_time &abstime, Event event, uint32_t label);
-
-  /**
    * @brief Schedule an event at relative time 'reltime'
    * @param reltime Relative time
    * @param event function to be called at the time
diff --git a/model/sync-event.h b/model/sync-event.h
new file mode 100644
index 0000000..7808947
--- /dev/null
+++ b/model/sync-event.h
@@ -0,0 +1,35 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef SYNC_EVENT_H
+#define SYNC_EVENT_H
+
+#include <boost/function.hpp>
+
+namespace Sync
+{
+
+typedef boost::function< void ( ) > Event;
+
+} // Sync
+
+#endif // SYNC_EVENT_H
diff --git a/model/sync-logic.cc b/model/sync-logic.cc
index 1e99e84..773f368 100644
--- a/model/sync-logic.cc
+++ b/model/sync-logic.cc
@@ -34,7 +34,9 @@
 using namespace std;
 using namespace boost;
 
-// INIT_LOGGER ("SyncLogic");
+#ifndef _STANDALONE
+INIT_LOGGER ("SyncLogic");
+#endif
 
 namespace Sync
 {
@@ -49,6 +51,7 @@
   , m_randomGenerator (static_cast<unsigned int> (std::time (0)))
   , m_rangeUniformRandom (m_randomGenerator, uniform_int<> (20,80))
 {
+#ifdef _STANDALONE
 #ifdef _DEBUG
 #ifdef HAVE_LOG4CXX
   // _LOG_FUNCTION (syncPrefix);
@@ -57,6 +60,7 @@
   id ++;
 #endif
 #endif
+#endif
   
   m_ccnxHandle->setInterestFilter (m_syncPrefix,
                                    bind (&SyncLogic::respondSyncInterest, this, _1));
diff --git a/ns3/sync-scheduler.cc b/ns3/sync-scheduler.cc
new file mode 100644
index 0000000..b236c02
--- /dev/null
+++ b/ns3/sync-scheduler.cc
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "sync-scheduler.h"
+#include "sync-log.h"
+
+#include "ns3/simulator.h"
+
+using namespace boost;
+using namespace std;
+
+INIT_LOGGER ("Scheduler");
+
+namespace Sync {
+
+Scheduler::Scheduler ()
+{
+}
+
+Scheduler::~Scheduler ()
+{
+}
+
+void
+Scheduler::schedule (const boost::posix_time::time_duration &reltime, Event event, uint32_t label)
+{
+  ns3::Seconds (reltime.total_seconds()) + ns3::MilliSeconds (reltime.milliseconds ()) + ns3::MicroSeconds (reltime.microseconds ());
+}
+
+void
+Scheduler::cancel (uint32_t label)
+{
+  // {
+  //   // cout << "Canceling label " << label << " size: " << m_events.size () << endl;
+  //   lock_guard<mutex> lock (m_eventsMutex);
+  //   m_events.get<byLabel> ().erase (label);
+  //   // cout << "Canceled label " << label << " size: " << m_events.size () << endl;
+  // }
+  // m_eventsCondition.notify_one ();
+  // m_thread.interrupt (); // interrupt sleep, if currently sleeping
+}
+
+
+} // Sync
diff --git a/ns3/sync-scheduler.h b/ns3/sync-scheduler.h
new file mode 100644
index 0000000..d3b536a
--- /dev/null
+++ b/ns3/sync-scheduler.h
@@ -0,0 +1,77 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef SYNC_SCHEDULER_H
+#define SYNC_SCHEDULER_H
+
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include "sync-event.h"
+
+namespace Sync {
+
+/**
+ * @ingroup sync
+ * @brief General purpose event scheduler
+ *
+ * This class internally runs a thread and events can be scheduled by specifying an absolute or relative time of the event
+ */
+class Scheduler
+{
+public:
+  /**
+   * @brief Default constructor. Thread will be created
+   */
+  Scheduler ();
+  /**
+   * @brief Destructor. Thread will be nicely stopped
+   */
+  ~Scheduler ();
+
+  /**
+   * @brief Schedule an event at absolute time 'abstime'
+   * @param abstime Absolute time
+   * @param event function to be called at the time
+   * @param label Label for the event
+   */
+  // void
+  // schedule (const boost::system_time &abstime, Event event, uint32_t label);
+
+  /**
+   * @brief Schedule an event at relative time 'reltime'
+   * @param reltime Relative time
+   * @param event function to be called at the time
+   * @param label Label for the event
+   */
+  void
+  schedule (const boost::posix_time::time_duration &reltime, Event event, uint32_t label); 
+
+  /**
+   * @brief Cancel all events for the label
+   * @param label Label of the event that needs to be cancelled
+   */
+  void
+  cancel (uint32_t label);
+};
+  
+}
+
+#endif // SYNC_SCHEDULER_H
diff --git a/wscript b/wscript
index 6f5667d..3eab13e 100644
--- a/wscript
+++ b/wscript
@@ -58,20 +58,6 @@
 
     conf.load('tinyxml')
     conf.check_tinyxml ()
-
-    # else:
-        # if 'CXXFLAGS' in conf.env:
-        #     tmp = conf.env['CXXFLAGS']
-        # else:
-        #     tmp = []
-        # conf.env['CXXFLAGS'] = tmp + ['-g']
-        # if 'CFLAGS' in conf.env:
-        #     tmp = conf.env['CFLAGS']
-        # else:
-        #     tmp = []
-        # conf.env['CFLAGS'] = tmp + ['-g']
-        # _report_optional_feature(conf, "debug", "Debug Symbols", True, '')
-
                    
 def build (bld):
     if bld.get_define ("NS3_MODULE"):
@@ -81,11 +67,12 @@
             source =  [
                 # 'ns3/sync-ccnx-wrapper.cc',
                 'ns3/sync-ns3-name-info.cc',
+                'ns3/sync-scheduler.cc',
                 
-                'model/sync-app-data-fetch.cc',
-                'model/sync-app-data-publish.cc',
-                'model/sync-app-socket-c.cc',
-                'model/sync-app-socket.cc',
+                # 'model/sync-app-data-fetch.cc',
+                # 'model/sync-app-data-publish.cc',
+                # 'ns3/sync-app.cc',
+
                 'model/sync-diff-leaf.cc',
                 'model/sync-diff-state.cc',
                 'model/sync-digest.cc',
@@ -114,11 +101,11 @@
                 'ccnx/sync-ccnx-wrapper.cc',
                 'ccnx/sync-scheduler.cc',
                 'ccnx/sync-log.cc',
-                
-                'model/sync-app-data-fetch.cc',
-                'model/sync-app-data-publish.cc',
-                'model/sync-app-socket-c.cc',
-                'model/sync-app-socket.cc',
+                'ccnx/sync-app-data-fetch.cc',
+                'ccnx/sync-app-data-publish.cc',
+                'ccnx/sync-app-socket-c.cc',
+                'ccnx/sync-app-socket.cc',
+
                 'model/sync-diff-leaf.cc',
                 'model/sync-diff-state.cc',
                 'model/sync-digest.cc',