diff --git a/src/communication/interest-manager.cpp b/src/communication/interest-manager.cpp
index 73a43e9..226efaf 100644
--- a/src/communication/interest-manager.cpp
+++ b/src/communication/interest-manager.cpp
@@ -17,8 +17,7 @@
 using namespace ndn;
 
 void
-InterestManager::processInterest(Nlsr& pnlsr,
-                                 const ndn::Name& name,
+InterestManager::processInterest(const ndn::Name& name,
                                  const ndn::Interest& interest)
 {
   cout << "<< I: " << interest << endl;
@@ -30,45 +29,45 @@
   {
     string nbr = nt.getTokenString(nt.getTokenPosition(chkString) + 1);
     cout << "Neighbor: " << nbr << endl;
-    processInterestInfo(pnlsr, nbr, interest);
+    processInterestInfo(nbr, interest);
   }
   chkString = "LSA";
   if (nt.doesTokenExist(chkString))
   {
-    processInterestLsa(pnlsr, interest);
+    processInterestLsa(interest);
   }
   chkString = "keys";
   if (nt.doesTokenExist(chkString))
   {
-    processInterestKeys(pnlsr, interest);
+    processInterestKeys(interest);
   }
 }
 
 void
-InterestManager::processInterestInfo(Nlsr& pnlsr, string& neighbor,
+InterestManager::processInterestInfo(const string& neighbor,
                                      const ndn::Interest& interest)
 {
-  if (pnlsr.getAdl().isNeighbor(neighbor))
+  if (m_nlsr.getAdl().isNeighbor(neighbor))
   {
     Data data(ndn::Name(interest.getName()).appendVersion());
     data.setFreshnessPeriod(time::seconds(10)); // 10 sec
     data.setContent((const uint8_t*)"info", sizeof("info"));
-    pnlsr.getKeyManager().signData(data);
+    m_nlsr.getKeyManager().signData(data);
     cout << ">> D: " << data << endl;
-    pnlsr.getNlsrFace()->put(data);
-    int status = pnlsr.getAdl().getStatusOfNeighbor(neighbor);
+    m_nlsr.getNlsrFace()->put(data);
+    int status = m_nlsr.getAdl().getStatusOfNeighbor(neighbor);
     if (status == 0)
     {
       string intName = neighbor + "/" + "info" +
-                       pnlsr.getConfParameter().getRouterPrefix();
-      expressInterest(pnlsr, intName, 2,
-                      pnlsr.getConfParameter().getInterestResendTime());
+                       m_nlsr.getConfParameter().getRouterPrefix();
+      expressInterest(intName, 2,
+                      m_nlsr.getConfParameter().getInterestResendTime());
     }
   }
 }
 
 void
-InterestManager::processInterestLsa(Nlsr& pnlsr, const ndn::Interest& interest)
+InterestManager::processInterestLsa(const ndn::Interest& interest)
 {
   string intName = interest.getName().toUri();
   Tokenizer nt(intName, "/");
@@ -94,17 +93,17 @@
   std::cout << "Ls Type: " << interestedLsType << std::endl;
   if (lsTypeString == "1") //Name Lsa
   {
-    processInterestForNameLsa(pnlsr, interest,
+    processInterestForNameLsa(interest,
                               origRouter + "/" + lsTypeString, interestedLsSeqNo);
   }
   else if (lsTypeString == "2") //Adj Lsa
   {
-    processInterestForAdjLsa(pnlsr, interest,
+    processInterestForAdjLsa(interest,
                              origRouter + "/" + lsTypeString, interestedLsSeqNo);
   }
   else if (lsTypeString == "3") //Cor Lsa
   {
-    processInterestForCorLsa(pnlsr, interest,
+    processInterestForCorLsa(interest,
                              origRouter + "/" + lsTypeString, interestedLsSeqNo);
   }
   else
@@ -114,70 +113,67 @@
 }
 
 void
-InterestManager::processInterestForNameLsa(Nlsr& pnlsr,
-                                           const ndn::Interest& interest,
-                                           string lsaKey, uint32_t interestedlsSeqNo)
+InterestManager::processInterestForNameLsa(const ndn::Interest& interest,
+                                           const string& lsaKey, uint32_t interestedlsSeqNo)
 {
-  std::pair<NameLsa&, bool>  nameLsa = pnlsr.getLsdb().getNameLsa(lsaKey);
-  if (nameLsa.second)
+  NameLsa*  nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
+  if (nameLsa != 0)
   {
-    if (nameLsa.first.getLsSeqNo() >= interestedlsSeqNo)
+    if (nameLsa->getLsSeqNo() >= interestedlsSeqNo)
     {
       Data data(ndn::Name(interest.getName()).appendVersion());
       data.setFreshnessPeriod(time::seconds(10)); // 10 sec
-      string content = nameLsa.first.getData();
+      string content = nameLsa->getData();
       data.setContent((const uint8_t*)content.c_str(), content.size());
-      pnlsr.getKeyManager().signData(data);
+      m_nlsr.getKeyManager().signData(data);
       std::cout << ">> D: " << data << std::endl;
-      pnlsr.getNlsrFace()->put(data);
+      m_nlsr.getNlsrFace()->put(data);
     }
   }
 }
 
 void
-InterestManager::processInterestForAdjLsa(Nlsr& pnlsr,
-                                          const ndn::Interest& interest,
-                                          string lsaKey, uint32_t interestedlsSeqNo)
+InterestManager::processInterestForAdjLsa(const ndn::Interest& interest,
+                                          const string& lsaKey, uint32_t interestedlsSeqNo)
 {
-  std::pair<AdjLsa&, bool> adjLsa = pnlsr.getLsdb().getAdjLsa(lsaKey);
-  if (adjLsa.second)
+  AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
+  if (adjLsa != 0)
   {
-    if (adjLsa.first.getLsSeqNo() >= interestedlsSeqNo)
+    if (adjLsa->getLsSeqNo() >= interestedlsSeqNo)
     {
       Data data(ndn::Name(interest.getName()).appendVersion());
       data.setFreshnessPeriod(time::seconds(10)); // 10 sec
-      string content = adjLsa.first.getData();
+      string content = adjLsa->getData();
       data.setContent((const uint8_t*)content.c_str(), content.size());
-      pnlsr.getKeyManager().signData(data);
+      m_nlsr.getKeyManager().signData(data);
       std::cout << ">> D: " << data << std::endl;
-      pnlsr.getNlsrFace()->put(data);
+      m_nlsr.getNlsrFace()->put(data);
     }
   }
 }
 
 void
-InterestManager::processInterestForCorLsa(Nlsr& pnlsr,
-                                          const ndn::Interest& interest,
-                                          string lsaKey, uint32_t interestedlsSeqNo)
+InterestManager::processInterestForCorLsa(const ndn::Interest& interest,
+                                          const string& lsaKey, uint32_t interestedlsSeqNo)
 {
-  std::pair<CorLsa&, bool> corLsa = pnlsr.getLsdb().getCorLsa(lsaKey);
-  if (corLsa.second)
+  CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
+  if (corLsa != 0)
   {
-    if (corLsa.first.getLsSeqNo() >= interestedlsSeqNo)
+    if (corLsa->getLsSeqNo() >= interestedlsSeqNo)
     {
       Data data(ndn::Name(interest.getName()).appendVersion());
       data.setFreshnessPeriod(time::seconds(10)); // 10 sec
-      string content = corLsa.first.getData();
+      string content = corLsa->getData();
       data.setContent((const uint8_t*)content.c_str(), content.size());
-      pnlsr.getKeyManager().signData(data);
+      m_nlsr.getKeyManager().signData(data);
       std::cout << ">> D: " << data << std::endl;
-      pnlsr.getNlsrFace()->put(data);
+      m_nlsr.getNlsrFace()->put(data);
     }
   }
 }
 
 void
-InterestManager::processInterestKeys(Nlsr& pnlsr, const ndn::Interest& interest)
+InterestManager::processInterestKeys(const ndn::Interest& interest)
 {
   std::cout << "processInterestKeys called " << std::endl;
   string intName = interest.getName().toUri();
@@ -192,14 +188,14 @@
   {
     certName = nt.getTokenString(0, nt.getTokenNumber() - 1);
     cout << "Cert Name: " << certName << std::endl;
-    chkCert = pnlsr.getKeyManager().getCertificateFromStore(certName);
+    chkCert = m_nlsr.getKeyManager().getCertificateFromStore(certName);
   }
   else
   {
     certName = nt.getTokenString(0, nt.getTokenNumber() - 2);
     seqNum = boost::lexical_cast<uint32_t>(nt.getToken(nt.getTokenNumber() - 1));
     std::cout << "Cert Name: " << certName << " Seq Num: " << seqNum << std::endl;
-    chkCert = pnlsr.getKeyManager().getCertificateFromStore(certName, seqNum);
+    chkCert = m_nlsr.getKeyManager().getCertificateFromStore(certName, seqNum);
   }
   if (chkCert.second)
   {
@@ -208,7 +204,7 @@
       std::string dn;
       dataName = ndn::Name(interest.getName()).appendVersion();
       std::pair<uint32_t, bool> seqChk =
-        pnlsr.getKeyManager().getCertificateSeqNum(certName);
+        m_nlsr.getKeyManager().getCertificateSeqNum(certName);
       if (seqChk.second)
       {
         dn = dataName.toUri() + "/" + boost::lexical_cast<std::string>(seqChk.first);
@@ -219,7 +215,6 @@
         dn = dataName.toUri() + "/" + boost::lexical_cast<std::string>(10);
         dataName = ndn::Name(dn);
       }
-
     }
     else
     {
@@ -228,15 +223,14 @@
     Data data(dataName.appendVersion());
     data.setFreshnessPeriod(time::seconds(10)); //10 sec
     data.setContent(chkCert.first->wireEncode());
-    pnlsr.getKeyManager().signData(data);
-    pnlsr.getNlsrFace()->put(data);
+    m_nlsr.getKeyManager().signData(data);
+    m_nlsr.getNlsrFace()->put(data);
   }
 }
 
 
 void
-InterestManager::processInterestTimedOut(Nlsr& pnlsr,
-                                         const ndn::Interest& interest)
+InterestManager::processInterestTimedOut(const ndn::Interest& interest)
 {
   std::cout << "Timed out interest : " << interest.getName().toUri() << std::endl;
   string intName = interest.getName().toUri();
@@ -245,94 +239,92 @@
   if (nt.doesTokenExist(chkString))
   {
     string nbr = nt.getTokenString(0, nt.getTokenPosition(chkString) - 1);
-    processInterestTimedOutInfo(pnlsr , nbr , interest);
+    processInterestTimedOutInfo(nbr , interest);
   }
   chkString = "LSA";
   if (nt.doesTokenExist(chkString))
   {
-    processInterestTimedOutLsa(pnlsr, interest);
+    processInterestTimedOutLsa(interest);
   }
 }
 
 void
-InterestManager::processInterestTimedOutInfo(Nlsr& pnlsr, string& neighbor,
+InterestManager::processInterestTimedOutInfo(const string& neighbor,
                                              const ndn::Interest& interest)
 {
-  pnlsr.getAdl().incrementTimedOutInterestCount(neighbor);
-  int status = pnlsr.getAdl().getStatusOfNeighbor(neighbor);
-  int infoIntTimedOutCount = pnlsr.getAdl().getTimedOutInterestCount(neighbor);
+  m_nlsr.getAdl().incrementTimedOutInterestCount(neighbor);
+  int status = m_nlsr.getAdl().getStatusOfNeighbor(neighbor);
+  int infoIntTimedOutCount = m_nlsr.getAdl().getTimedOutInterestCount(neighbor);
   std::cout << "Neighbor: " << neighbor << std::endl;
   std::cout << "Status: " << status << std::endl;
   std::cout << "Info Interest Timed out: " << infoIntTimedOutCount << std::endl;
-  if ((infoIntTimedOutCount < pnlsr.getConfParameter().getInterestRetryNumber()))
+  if ((infoIntTimedOutCount < m_nlsr.getConfParameter().getInterestRetryNumber()))
   {
     string intName = neighbor + "/" + "info" +
-                     pnlsr.getConfParameter().getRouterPrefix();
-    expressInterest(pnlsr, intName, 2,
-                    pnlsr.getConfParameter().getInterestResendTime());
+                     m_nlsr.getConfParameter().getRouterPrefix();
+    expressInterest(intName, 2,
+                    m_nlsr.getConfParameter().getInterestResendTime());
   }
   else if ((status == 1) &&
-           (infoIntTimedOutCount == pnlsr.getConfParameter().getInterestRetryNumber()))
+           (infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber()))
   {
-    pnlsr.getAdl().setStatusOfNeighbor(neighbor, 0);
-    pnlsr.incrementAdjBuildCount();
-    if (pnlsr.getIsBuildAdjLsaSheduled() == 0)
+    m_nlsr.getAdl().setStatusOfNeighbor(neighbor, 0);
+    m_nlsr.incrementAdjBuildCount();
+    if (m_nlsr.getIsBuildAdjLsaSheduled() == 0)
     {
-      pnlsr.setIsBuildAdjLsaSheduled(1);
+      m_nlsr.setIsBuildAdjLsaSheduled(1);
       // event here
-      pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
-                                         ndn::bind(&Lsdb::scheduledAdjLsaBuild,
-                                                   &pnlsr.getLsdb(),
-                                                   boost::ref(pnlsr)));
+      m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
+                                          ndn::bind(&Lsdb::scheduledAdjLsaBuild,
+                                                    &m_nlsr.getLsdb(),
+                                                    boost::ref(m_nlsr)));
     }
   }
 }
 
 void
-InterestManager::processInterestTimedOutLsa(Nlsr& pnlsr,
-                                            const ndn::Interest& interest)
+InterestManager::processInterestTimedOutLsa(const ndn::Interest& interest)
 {
 }
 
 void
-InterestManager::expressInterest(Nlsr& pnlsr, const string& interestNamePrefix,
+InterestManager::expressInterest(const string& interestNamePrefix,
                                  int scope, int seconds)
 {
   std::cout << "Expressing Interest :" << interestNamePrefix << std::endl;
   ndn::Interest i((ndn::Name(interestNamePrefix)));
   i.setInterestLifetime(time::seconds(seconds));
   i.setMustBeFresh(true);
-  pnlsr.getNlsrFace()->expressInterest(i,
-                                       ndn::func_lib::bind(&DataManager::processContent,
-                                                           &pnlsr.getDm(),
-                                                           boost::ref(pnlsr), _1,
-                                                           _2, boost::ref(*this)),
-                                       ndn::func_lib::bind(&InterestManager::processInterestTimedOut,
-                                                           this, boost::ref(pnlsr), _1));
+  m_nlsr.getNlsrFace()->expressInterest(i,
+                                        ndn::bind(&DataManager::processContent,
+                                                  &m_nlsr.getDm(),
+                                                  _1, _2, boost::ref(*this)),
+                                        ndn::bind(&InterestManager::processInterestTimedOut,
+                                                  this, _1));
 }
 
 
 void
-InterestManager::sendScheduledInfoInterest(Nlsr& pnlsr, int seconds)
+InterestManager::sendScheduledInfoInterest(int seconds)
 {
-  std::list<Adjacent> adjList = pnlsr.getAdl().getAdjList();
+  std::list<Adjacent> adjList = m_nlsr.getAdl().getAdjList();
   for (std::list<Adjacent>::iterator it = adjList.begin(); it != adjList.end();
        ++it)
   {
     string adjName = (*it).getName() + "/" + "info" +
-                     pnlsr.getConfParameter().getRouterPrefix();
-    expressInterest(pnlsr, adjName, 2,
-                    pnlsr.getConfParameter().getInterestResendTime());
+                     m_nlsr.getConfParameter().getRouterPrefix();
+    expressInterest(adjName, 2,
+                    m_nlsr.getConfParameter().getInterestResendTime());
   }
-  scheduleInfoInterest(pnlsr, pnlsr.getConfParameter().getInfoInterestInterval());
+  scheduleInfoInterest(m_nlsr.getConfParameter().getInfoInterestInterval());
 }
 
 void
-InterestManager::scheduleInfoInterest(Nlsr& pnlsr, int seconds)
+InterestManager::scheduleInfoInterest(int seconds)
 {
-  EventId eid = pnlsr.getScheduler().scheduleEvent(ndn::time::seconds(seconds),
-                                                   ndn::bind(&InterestManager::sendScheduledInfoInterest, this,
-                                                             boost::ref(pnlsr), seconds));
+  EventId eid = m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(seconds),
+                                                    ndn::bind(&InterestManager::sendScheduledInfoInterest, this,
+                                                              seconds));
 }
 
 
