diff --git a/tools/peek/ndn-peek.cpp b/tools/peek/ndn-peek.cpp
index 5460096..4caba0a 100644
--- a/tools/peek/ndn-peek.cpp
+++ b/tools/peek/ndn-peek.cpp
@@ -31,13 +31,14 @@
 
 #include <ndn-cxx/face.hpp>
 
-namespace ndntlvpeek {
+namespace ndn {
+namespace peek {
 
-class NdnTlvPeek : boost::noncopyable
+class NdnPeek : boost::noncopyable
 {
 public:
   explicit
-  NdnTlvPeek(char* programName)
+  NdnPeek(char* programName)
     : m_programName(programName)
     , m_mustBeFresh(false)
     , m_isChildSelectorRightmost(false)
@@ -87,6 +88,7 @@
   {
     if (minSuffixComponents < 0)
       usage();
+
     m_minSuffixComponents = minSuffixComponents;
   }
 
@@ -95,6 +97,7 @@
   {
     if (maxSuffixComponents < 0)
       usage();
+
     m_maxSuffixComponents = maxSuffixComponents;
   }
 
@@ -103,7 +106,8 @@
   {
     if (interestLifetime < 0)
       usage();
-    m_interestLifetime = ndn::time::milliseconds(interestLifetime);
+
+    m_interestLifetime = time::milliseconds(interestLifetime);
   }
 
   void
@@ -117,87 +121,90 @@
   {
     if (timeout < 0)
       usage();
-    m_timeout = ndn::time::milliseconds(timeout);
+
+    m_timeout = time::milliseconds(timeout);
   }
 
   void
   setPrefixName(char* prefixName)
   {
     m_prefixName = prefixName;
+
     if (m_prefixName.length() == 0)
       usage();
   }
 
-  ndn::time::milliseconds
+  time::milliseconds
   getDefaultInterestLifetime()
   {
-    return ndn::time::seconds(4);
+    return time::seconds(4);
   }
 
-  ndn::Interest
+  Interest
   createInterestPacket()
   {
-    ndn::Name interestName(m_prefixName);
-    ndn::Interest interestPacket(interestName);
+    Name interestName(m_prefixName);
+    Interest interestPacket(interestName);
+
     if (m_mustBeFresh)
       interestPacket.setMustBeFresh(true);
+
     if (m_isChildSelectorRightmost)
       interestPacket.setChildSelector(1);
+
     if (m_minSuffixComponents >= 0)
       interestPacket.setMinSuffixComponents(m_minSuffixComponents);
+
     if (m_maxSuffixComponents >= 0)
       interestPacket.setMaxSuffixComponents(m_maxSuffixComponents);
-    if (m_interestLifetime < ndn::time::milliseconds::zero())
+
+    if (m_interestLifetime < time::milliseconds::zero())
       interestPacket.setInterestLifetime(getDefaultInterestLifetime());
     else
       interestPacket.setInterestLifetime(m_interestLifetime);
+
     return interestPacket;
   }
 
   void
-  onData(const ndn::Interest& interest, ndn::Data& data)
+  onData(const Interest& interest, Data& data)
   {
     m_isDataReceived = true;
-    if (m_isPayloadOnlySet)
-      {
-        const ndn::Block& block = data.getContent();
-        std::cout.write(reinterpret_cast<const char*>(block.value()), block.value_size());
-      }
-    else
-      {
-        const ndn::Block& block = data.wireEncode();
-        std::cout.write(reinterpret_cast<const char*>(block.wire()), block.size());
-      }
+    if (m_isPayloadOnlySet) {
+      const Block& block = data.getContent();
+      std::cout.write(reinterpret_cast<const char*>(block.value()), block.value_size());
+    }
+    else {
+      const Block& block = data.wireEncode();
+      std::cout.write(reinterpret_cast<const char*>(block.wire()), block.size());
+    }
   }
 
   void
-  onTimeout(const ndn::Interest& interest)
+  onTimeout(const Interest& interest)
   {
   }
 
   void
   run()
   {
-    try
-      {
-        m_face.expressInterest(createInterestPacket(),
-                               bind(&NdnTlvPeek::onData, this, _1, _2),
-                               bind(&NdnTlvPeek::onTimeout, this, _1));
-        if (m_timeout < ndn::time::milliseconds::zero())
-          {
-            if (m_interestLifetime < ndn::time::milliseconds::zero())
-              m_face.processEvents(getDefaultInterestLifetime());
-            else
-              m_face.processEvents(m_interestLifetime);
-          }
+    try {
+      m_face.expressInterest(createInterestPacket(),
+                             bind(&NdnPeek::onData, this, _1, _2),
+                             bind(&NdnPeek::onTimeout, this, _1));
+      if (m_timeout < time::milliseconds::zero()) {
+        if (m_interestLifetime < time::milliseconds::zero())
+          m_face.processEvents(getDefaultInterestLifetime());
         else
-          m_face.processEvents(m_timeout);
+          m_face.processEvents(m_interestLifetime);
       }
-    catch (std::exception& e)
-      {
-        std::cerr << "ERROR: " << e.what() << "\n" << std::endl;
-        exit(1);
-      }
+      else
+        m_face.processEvents(m_timeout);
+    }
+    catch (std::exception& e) {
+      std::cerr << "ERROR: " << e.what() << "\n" << std::endl;
+      exit(1);
+    }
   }
 
   bool
@@ -207,58 +214,55 @@
   }
 
 private:
-
   std::string m_programName;
   bool m_mustBeFresh;
   bool m_isChildSelectorRightmost;
   int m_minSuffixComponents;
   int m_maxSuffixComponents;
-  ndn::time::milliseconds m_interestLifetime;
+  time::milliseconds m_interestLifetime;
   bool m_isPayloadOnlySet;
-  ndn::time::milliseconds m_timeout;
+  time::milliseconds m_timeout;
   std::string m_prefixName;
   bool m_isDataReceived;
-  ndn::Face m_face;
+  Face m_face;
 };
 
-}
-
 int
 main(int argc, char* argv[])
 {
-  ndntlvpeek::NdnTlvPeek ndnTlvPeek(argv[0]);
+  NdnPeek program(argv[0]);
   int option;
   while ((option = getopt(argc, argv, "hfrm:M:l:pw:V")) != -1) {
     switch (option) {
     case 'h':
-      ndnTlvPeek.usage();
+      program.usage();
       break;
     case 'f':
-      ndnTlvPeek.setMustBeFresh();
+      program.setMustBeFresh();
       break;
     case 'r':
-      ndnTlvPeek.setRightmostChildSelector();
+      program.setRightmostChildSelector();
       break;
     case 'm':
-      ndnTlvPeek.setMinSuffixComponents(atoi(optarg));
+      program.setMinSuffixComponents(atoi(optarg));
       break;
     case 'M':
-      ndnTlvPeek.setMaxSuffixComponents(atoi(optarg));
+      program.setMaxSuffixComponents(atoi(optarg));
       break;
     case 'l':
-      ndnTlvPeek.setInterestLifetime(atoi(optarg));
+      program.setInterestLifetime(atoi(optarg));
       break;
     case 'p':
-      ndnTlvPeek.setPayloadOnly();
+      program.setPayloadOnly();
       break;
     case 'w':
-      ndnTlvPeek.setTimeout(atoi(optarg));
+      program.setTimeout(atoi(optarg));
       break;
     case 'V':
       std::cout << NFD_VERSION_BUILD_STRING << std::endl;
       return 0;
     default:
-      ndnTlvPeek.usage();
+      program.usage();
       break;
     }
   }
@@ -267,13 +271,22 @@
   argv += optind;
 
   if (argv[0] == 0)
-    ndnTlvPeek.usage();
+    program.usage();
 
-  ndnTlvPeek.setPrefixName(argv[0]);
-  ndnTlvPeek.run();
+  program.setPrefixName(argv[0]);
+  program.run();
 
-  if (ndnTlvPeek.isDataReceived())
+  if (program.isDataReceived())
     return 0;
   else
     return 1;
 }
+
+} // namespace peek
+} // namespace ndn
+
+int
+main(int argc, char** argv)
+{
+  return ndn::peek::main(argc, argv);
+}
diff --git a/tools/peek/ndn-poke.cpp b/tools/peek/ndn-poke.cpp
index 45db702..a4a635d 100644
--- a/tools/peek/ndn-poke.cpp
+++ b/tools/peek/ndn-poke.cpp
@@ -32,13 +32,14 @@
 #include <ndn-cxx/face.hpp>
 #include <ndn-cxx/security/key-chain.hpp>
 
-namespace ndntlvpoke {
+namespace ndn {
+namespace peek {
 
-class NdnTlvPoke : boost::noncopyable
+class NdnPoke : boost::noncopyable
 {
 public:
   explicit
-  NdnTlvPoke(char* programName)
+  NdnPoke(char* programName)
     : m_programName(programName)
     , m_isForceDataSet(false)
     , m_isUseDigestSha256Set(false)
@@ -84,7 +85,7 @@
   void
   setIdentityName(char* identityName)
   {
-    m_identityName = ndn::make_shared<ndn::Name>(identityName);
+    m_identityName = make_shared<Name>(identityName);
   }
 
   void
@@ -98,7 +99,8 @@
   {
     if (freshnessPeriod < 0)
       usage();
-    m_freshnessPeriod = ndn::time::milliseconds(freshnessPeriod);
+
+    m_freshnessPeriod = time::milliseconds(freshnessPeriod);
   }
 
   void
@@ -106,57 +108,60 @@
   {
     if (timeout < 0)
       usage();
-    m_timeout = ndn::time::milliseconds(timeout);
+
+    m_timeout = time::milliseconds(timeout);
   }
 
   void
   setPrefixName(char* prefixName)
   {
-    m_prefixName = ndn::Name(prefixName);
+    m_prefixName = Name(prefixName);
   }
 
-  ndn::time::milliseconds
+  time::milliseconds
   getDefaultTimeout()
   {
-    return ndn::time::seconds(10);
+    return time::seconds(10);
   }
 
-  ndn::Data
+  Data
   createDataPacket()
   {
-    ndn::Data dataPacket(m_prefixName);
+    Data dataPacket(m_prefixName);
+
     std::stringstream payloadStream;
     payloadStream << std::cin.rdbuf();
     std::string payload = payloadStream.str();
     dataPacket.setContent(reinterpret_cast<const uint8_t*>(payload.c_str()), payload.length());
-    if (m_freshnessPeriod >= ndn::time::milliseconds::zero())
+
+    if (m_freshnessPeriod >= time::milliseconds::zero())
       dataPacket.setFreshnessPeriod(m_freshnessPeriod);
-    if (m_isLastAsFinalBlockIdSet)
-      {
-        if (!m_prefixName.empty())
-          dataPacket.setFinalBlockId(m_prefixName.get(-1));
-        else
-          {
-            std::cerr << "Name Provided Has 0 Components" << std::endl;
-            exit(1);
-          }
+
+    if (m_isLastAsFinalBlockIdSet) {
+      if (!m_prefixName.empty())
+        dataPacket.setFinalBlockId(m_prefixName.get(-1));
+      else {
+        std::cerr << "Name Provided Has 0 Components" << std::endl;
+        exit(1);
       }
+    }
+
     if (m_isUseDigestSha256Set)
       m_keyChain.signWithSha256(dataPacket);
-    else
-      {
-        if (!static_cast<bool>(m_identityName))
-          m_keyChain.sign(dataPacket);
-        else
-          m_keyChain.signByIdentity(dataPacket, *m_identityName);
-      }
+    else {
+      if (m_identityName == nullptr)
+        m_keyChain.sign(dataPacket);
+      else
+        m_keyChain.signByIdentity(dataPacket, *m_identityName);
+    }
+
     return dataPacket;
   }
 
   void
-  onInterest(const ndn::Name& name,
-             const ndn::Interest& interest,
-             const ndn::Data& dataPacket)
+  onInterest(const Name& name,
+             const Interest& interest,
+             const Data& dataPacket)
   {
     m_face.put(dataPacket);
     m_isDataSent = true;
@@ -164,7 +169,7 @@
   }
 
   void
-  onRegisterFailed(const ndn::Name& prefix, const std::string& reason)
+  onRegisterFailed(const Name& prefix, const std::string& reason)
   {
     std::cerr << "Prefix Registration Failure." << std::endl;
     std::cerr << "Reason = " << reason << std::endl;
@@ -173,31 +178,28 @@
   void
   run()
   {
-    try
-      {
-        ndn::Data dataPacket = createDataPacket();
-        if (m_isForceDataSet)
-          {
-            m_face.put(dataPacket);
-            m_isDataSent = true;
-          }
-        else
-          {
-            m_face.setInterestFilter(m_prefixName,
-                                     bind(&NdnTlvPoke::onInterest, this, _1, _2, dataPacket),
-                                     ndn::RegisterPrefixSuccessCallback(),
-                                     bind(&NdnTlvPoke::onRegisterFailed, this, _1, _2));
-          }
-        if (m_timeout < ndn::time::milliseconds::zero())
-          m_face.processEvents(getDefaultTimeout());
-        else
-          m_face.processEvents(m_timeout);
+    try {
+      Data dataPacket = createDataPacket();
+      if (m_isForceDataSet) {
+        m_face.put(dataPacket);
+        m_isDataSent = true;
       }
-    catch (std::exception& e)
-      {
-        std::cerr << "ERROR: " << e.what() << "\n" << std::endl;
-        exit(1);
+      else {
+        m_face.setInterestFilter(m_prefixName,
+                                 bind(&NdnPoke::onInterest, this, _1, _2, dataPacket),
+                                 RegisterPrefixSuccessCallback(),
+                                 bind(&NdnPoke::onRegisterFailed, this, _1, _2));
       }
+
+      if (m_timeout < time::milliseconds::zero())
+        m_face.processEvents(getDefaultTimeout());
+      else
+        m_face.processEvents(m_timeout);
+    }
+    catch (std::exception& e) {
+      std::cerr << "ERROR: " << e.what() << "\n" << std::endl;
+      exit(1);
+    }
   }
 
   bool
@@ -207,56 +209,52 @@
   }
 
 private:
-
-  ndn::KeyChain m_keyChain;
+  KeyChain m_keyChain;
   std::string m_programName;
   bool m_isForceDataSet;
   bool m_isUseDigestSha256Set;
-  ndn::shared_ptr<ndn::Name> m_identityName;
+  shared_ptr<Name> m_identityName;
   bool m_isLastAsFinalBlockIdSet;
-  ndn::time::milliseconds m_freshnessPeriod;
-  ndn::time::milliseconds m_timeout;
-  ndn::Name m_prefixName;
+  time::milliseconds m_freshnessPeriod;
+  time::milliseconds m_timeout;
+  Name m_prefixName;
   bool m_isDataSent;
-  ndn::Face m_face;
-
+  Face m_face;
 };
 
-}
-
 int
 main(int argc, char* argv[])
 {
   int option;
-  ndntlvpoke::NdnTlvPoke ndnTlvPoke(argv[0]);
+  NdnPoke program(argv[0]);
   while ((option = getopt(argc, argv, "hfDi:Fx:w:V")) != -1) {
     switch (option) {
     case 'h':
-      ndnTlvPoke.usage();
+      program.usage();
       break;
     case 'f':
-      ndnTlvPoke.setForceData();
+      program.setForceData();
       break;
     case 'D':
-      ndnTlvPoke.setUseDigestSha256();
+      program.setUseDigestSha256();
       break;
     case 'i':
-      ndnTlvPoke.setIdentityName(optarg);
+      program.setIdentityName(optarg);
       break;
     case 'F':
-      ndnTlvPoke.setLastAsFinalBlockId();
+      program.setLastAsFinalBlockId();
       break;
     case 'x':
-      ndnTlvPoke.setFreshnessPeriod(atoi(optarg));
+      program.setFreshnessPeriod(atoi(optarg));
       break;
     case 'w':
-      ndnTlvPoke.setTimeout(atoi(optarg));
+      program.setTimeout(atoi(optarg));
       break;
     case 'V':
       std::cout << NFD_VERSION_BUILD_STRING << std::endl;
       return 0;
     default:
-      ndnTlvPoke.usage();
+      program.usage();
       break;
     }
   }
@@ -265,13 +263,22 @@
   argv += optind;
 
   if (argv[0] == 0)
-    ndnTlvPoke.usage();
+    program.usage();
 
-  ndnTlvPoke.setPrefixName(argv[0]);
-  ndnTlvPoke.run();
+  program.setPrefixName(argv[0]);
+  program.run();
 
-  if (ndnTlvPoke.isDataSent())
+  if (program.isDataSent())
     return 0;
   else
     return 1;
 }
+
+} // namespace peek
+} // namespace ndn
+
+int
+main(int argc, char** argv)
+{
+  return ndn::peek::main(argc, argv);
+}
