diff --git a/tools/ndncatchunks3.cpp b/tools/ndncatchunks3.cpp
index 59a75ad..460ed52 100644
--- a/tools/ndncatchunks3.cpp
+++ b/tools/ndncatchunks3.cpp
@@ -20,27 +20,29 @@
 
 #include "face.hpp"
 
+namespace ndn {
+
 class Consumer
 {
 public:
-  Consumer(const std::string& data_name,
-           size_t pipe_size, size_t total_seg,
+  Consumer(const std::string& dataName,
+           size_t pipeSize, size_t nTotalSegments,
            int scope = -1, bool mustBeFresh = true)
-    : m_data_name(data_name)
-    , m_pipe_size(pipe_size)
-    , m_total_seg(total_seg)
-    , m_next_seg(0)
-    , m_total_size(0)
-    , m_output(false)
+    : m_dataName(dataName)
+    , m_pipeSize(pipeSize)
+    , m_nTotalSegments(nTotalSegments)
+    , m_nextSegment(0)
+    , m_totalSize(0)
+    , m_isOutputEnabled(false)
     , m_scope(scope)
     , m_mustBeFresh(mustBeFresh)
   {
   }
 
   inline void
-  enable_output()
+  enableOutput()
   {
-    m_output = true;
+    m_isOutputEnabled = true;
   }
 
   void
@@ -48,18 +50,18 @@
 
 private:
   void
-  on_data(const ndn::Interest& interest, ndn::Data& data);
+  onData(const Interest& interest, Data& data);
 
   void
-  on_timeout(const ndn::Interest& interest);
+  onTimeout(const Interest& interest);
 
-  ndn::Face m_face;
-  ndn::Name m_data_name;
-  size_t m_pipe_size;
-  size_t m_total_seg;
-  size_t m_next_seg;
-  size_t m_total_size;
-  bool m_output;  // set to false by default
+  Face m_face;
+  Name m_dataName;
+  size_t m_pipeSize;
+  size_t m_nTotalSegments;
+  size_t m_nextSegment;
+  size_t m_totalSize;
+  bool m_isOutputEnabled;  // set to false by default
 
   int m_scope;
   bool m_mustBeFresh;
@@ -70,18 +72,18 @@
 {
   try
     {
-      for (size_t i = 0; i < m_pipe_size; i++)
-	{
-          ndn::Interest interest(ndn::Name(m_data_name).appendSegment(m_next_seg++));
-	  interest.setInterestLifetime(ndn::time::milliseconds(4000));
-	  if (m_scope >= 0)
+      for (size_t i = 0; i < m_pipeSize; i++)
+        {
+          Interest interest(Name(m_dataName).appendSegment(m_nextSegment++));
+          interest.setInterestLifetime(time::milliseconds(4000));
+          if (m_scope >= 0)
             interest.setScope(m_scope);
-	  interest.setMustBeFresh(m_mustBeFresh);
+          interest.setMustBeFresh(m_mustBeFresh);
 
-	  m_face.expressInterest(interest,
-                                 ndn::bind(&Consumer::on_data, this, _1, _2),
-                                 ndn::bind(&Consumer::on_timeout, this, _1));
-	}
+          m_face.expressInterest(interest,
+                                 bind(&Consumer::onData, this, _1, _2),
+                                 bind(&Consumer::onTimeout, this, _1));
+        }
 
       // processEvents will block until the requested data received or timeout occurs
       m_face.processEvents();
@@ -93,85 +95,86 @@
 }
 
 void
-Consumer::on_data(const ndn::Interest& interest, ndn::Data& data)
+Consumer::onData(const Interest& interest, Data& data)
 {
-  const ndn::Block& content = data.getContent();
-  const ndn::Name& name = data.getName();
+  const Block& content = data.getContent();
+  const Name& name = data.getName();
 
-  if (m_output)
+  if (m_isOutputEnabled)
     {
       std::cout.write(reinterpret_cast<const char*>(content.value()), content.value_size());
     }
 
-  m_total_size += content.value_size();
+  m_totalSize += content.value_size();
 
-  if (name[-1].toSegment() + 1 == m_total_seg)
+  if (name[-1].toSegment() + 1 == m_nTotalSegments)
     {
       std::cerr << "Last segment received." << std::endl;
-      std::cerr << "Total # bytes of content received: " << m_total_size << std::endl;
+      std::cerr << "Total # bytes of content received: " << m_totalSize << std::endl;
     }
   else
     {
       // Send interest for next segment
-      ndn::Interest interest(ndn::Name(m_data_name).appendSegment(m_next_seg++));
+      Interest interest(Name(m_dataName).appendSegment(m_nextSegment++));
       if (m_scope >= 0)
         interest.setScope(m_scope);
-      interest.setInterestLifetime(ndn::time::milliseconds(4000));
+      interest.setInterestLifetime(time::milliseconds(4000));
       interest.setMustBeFresh(m_mustBeFresh);
 
       m_face.expressInterest(interest,
-                             ndn::bind(&Consumer::on_data, this, _1, _2),
-                             ndn::bind(&Consumer::on_timeout, this, _1));
+                             bind(&Consumer::onData, this, _1, _2),
+                             bind(&Consumer::onTimeout, this, _1));
     }
 }
 
 
 void
-Consumer::on_timeout(const ndn::Interest& interest)
+Consumer::onTimeout(const Interest& interest)
 {
   //XXX: currently no retrans
-  std::cerr << "TIMEOUT: last interest sent for segment #" << (m_next_seg - 1) << std::endl;
+  std::cerr << "TIMEOUT: last interest sent for segment #" << (m_nextSegment - 1) << std::endl;
 }
 
 
 int
 usage(const std::string &filename)
 {
-  std::cerr << "Usage: \n    " << filename << " [-p pipe_size] [-c total_segment] [-o] /ndn/name\n";
+  std::cerr << "Usage: \n    "
+            << filename << " [-p pipeSize] [-c nTotalSegmentsment] [-o] /ndn/name\n";
   return 1;
 }
 
 
 int
-main(int argc, char **argv)
+main(int argc, char** argv)
 {
   std::string name;
-  int pipe_size = 1;
-  int total_seg = std::numeric_limits<int>::max();
+  int pipeSize = 1;
+  int nTotalSegments = std::numeric_limits<int>::max();
   bool output = false;
 
   int opt;
   while ((opt = getopt(argc, argv, "op:c:")) != -1)
     {
-      switch(opt)
-	{
+      switch (opt)
+        {
         case 'p':
-	  pipe_size = atoi(optarg);
-	  if (pipe_size <= 0)
-	    pipe_size = 1;
-	  std::cerr << "main(): set pipe size = " << pipe_size << std::endl;
-	  break;
-	case 'c':
-	  total_seg = atoi(optarg);
-	  if (total_seg <= 0)
-	    total_seg = 1;
-	  std::cerr << "main(): set total seg = " << total_seg << std::endl;
-	  break;
-	case 'o':
-	  output = true;
-	  break;
+          pipeSize = atoi(optarg);
+          if (pipeSize <= 0)
+            pipeSize = 1;
+          std::cerr << "main(): set pipe size = " << pipeSize << std::endl;
+          break;
+        case 'c':
+          nTotalSegments = atoi(optarg);
+          if (nTotalSegments <= 0)
+            nTotalSegments = 1;
+          std::cerr << "main(): set total seg = " << nTotalSegments << std::endl;
+          break;
+        case 'o':
+          output = true;
+          break;
         default:
-	  return usage(argv[0]);
+          return usage(argv[0]);
         }
     }
 
@@ -185,12 +188,20 @@
       return usage(argv[0]);
     }
 
-  Consumer consumer(name, pipe_size, total_seg);
+  Consumer consumer(name, pipeSize, nTotalSegments);
 
   if (output)
-    consumer.enable_output();
+    consumer.enableOutput();
 
   consumer.run();
 
   return 0;
 }
+
+} // namespace ndn
+
+int
+main(int argc, char** argv)
+{
+  return ndn::main(argc, argv);
+}
