ContentObject and Interest serialization and deserialization seem to
work normal now.  Debug examples added to examples/ folder (they
probably should become a part of test suite).
diff --git a/examples/content-object-example.cc b/examples/content-object-example.cc
new file mode 100644
index 0000000..fa9700e
--- /dev/null
+++ b/examples/content-object-example.cc
@@ -0,0 +1,56 @@
+#include "ns3/test.h"
+#include "ns3/annotated-topology-reader.h"
+#include "ns3/ccnx-content-object-header.h"
+#include "ns3/uinteger.h"
+#include "ns3/random-variable.h"
+#include <limits> 
+#include "ns3/ccnx-header-helper.h"
+#include "ns3/header.h"
+#include "ns3/ccnx-name-components.h"
+#include "ns3/nstime.h"
+#include "ns3/buffer.h"
+#include "ns3/log.h"
+
+using namespace ns3;
+#include <fstream>
+
+NS_LOG_COMPONENT_DEFINE ("ContentObjectHeaderExample");
+
+int
+main (int argc, char *argv[])
+{
+	LogComponentEnable ("ContentObjectHeaderExample", LOG_ALL);
+	LogComponentEnable ("Packet", LOG_ALL);
+	
+    NS_LOG_INFO ("Test started");
+
+	Packet::EnablePrinting ();
+	Packet::EnableChecking (); 
+	Packet packet (10);
+	
+    CcnxContentObjectHeader header;
+	CcnxContentObjectTail   trailer;
+	
+    Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> ();
+    (*testname) ("1");
+    header.SetName(testname);
+
+	NS_LOG_INFO ("Source: \n" << header << trailer);
+
+	packet.AddHeader (header);
+	packet.AddTrailer (trailer);
+
+	// NS_LOG_INFO ("Deserialized packet: \n" << packet);
+
+	NS_LOG_INFO ("Removing and deserializing individual headers");
+	
+    CcnxContentObjectHeader dst_header;
+	CcnxContentObjectTail   dst_trailer;
+
+	packet.RemoveHeader (dst_header);
+	packet.RemoveTrailer (dst_trailer);
+	
+	NS_LOG_INFO ("Target: \n" << dst_header << dst_trailer);
+
+	return 0;
+}
diff --git a/examples/interest-header-example.cc b/examples/interest-header-example.cc
index 83895ad..2b595b1 100644
--- a/examples/interest-header-example.cc
+++ b/examples/interest-header-example.cc
@@ -20,9 +20,14 @@
 main (int argc, char *argv[])
 {
 	LogComponentEnable ("InterestHeaderExample", LOG_ALL);
+	LogComponentEnable ("Packet", LOG_ALL);
 	
     NS_LOG_INFO ("Test started");
 
+	Packet::EnablePrinting ();
+	Packet::EnableChecking (); 
+	Packet packet (0);
+
     CcnxInterestHeader interestHeader;
 	
     Ptr<CcnxNameComponents> testname = Create<CcnxNameComponents> ();
@@ -48,32 +53,17 @@
 	UniformVariable random(1, std::numeric_limits<uint32_t>::max ());
     uint32_t randomNonce = static_cast<uint32_t> (random.GetValue());
     interestHeader.SetNonce(randomNonce);
-	NS_LOG_INFO ("Source: \n" <<interestHeader);
+	NS_LOG_INFO ("Source: \n" << interestHeader);
     
-    uint32_t size = interestHeader.GetSerializedSize();
-    NS_LOG_INFO ("GetSerializedSize = " << size);
-    //uint32_t size = 5;
-    //NS_TEST_ASSERT_MSG_EQ (false, true, "GetSize = " << size);
-    
-    Buffer buf;
-	buf.AddAtStart (size);
-    Buffer::Iterator iter = buf.Begin ();
-    //interestHeader.
-    interestHeader.Serialize(iter);
+	packet.AddHeader (interestHeader);
+	NS_LOG_INFO ("Deserialized packet: " << packet);
 
-	std::ofstream of( "/tmp/file" );
-	of.write (reinterpret_cast<const char*> (buf.PeekData ()), size);
-	of.close ();
-
-	NS_LOG_INFO ("start = " << buf.GetCurrentStartOffset () << " " <<
-				 "end = " << buf.GetCurrentEndOffset ());	
+	NS_LOG_INFO ("Removing and deserializing individual headers");
 	
-    iter = buf.Begin ();
     CcnxInterestHeader target;
-	NS_LOG_INFO ("Trying to deserialize");
-	std::cout << "\n";
-	size = target.Deserialize (iter);
-	buf.RemoveAtEnd (size);
-	NS_LOG_INFO ("Deserialized size = " << size);
+	packet.RemoveHeader (target);
+
 	NS_LOG_INFO ("Target: \n" << target);
+
+	return 0;
 }
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-blob.cc b/helper/ccnb-parser/syntax-tree/ccnb-parser-blob.cc
index a0a112c..690f30d 100644
--- a/helper/ccnb-parser/syntax-tree/ccnb-parser-blob.cc
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-blob.cc
@@ -37,6 +37,7 @@
     }
   if (i < length && start.IsEnd ())
     throw CcnbDecodingException ();
+  // Block::counter += length;
 }
 
 Blob::~Blob ()
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-block.cc b/helper/ccnb-parser/syntax-tree/ccnb-parser-block.cc
index 2af8aef..d0f795f 100644
--- a/helper/ccnb-parser/syntax-tree/ccnb-parser-block.cc
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-block.cc
@@ -36,8 +36,11 @@
 const uint8_t CCN_MAX_TINY= ((1 << (7-CCN_TT_BITS)) - 1);
 const uint8_t CCN_TT_HBIT = ((uint8_t)(1 << 7));
 
+// int Block::counter = 0;
+
 Ptr<Block> Block::ParseBlock (Buffer::Iterator &start)
 {
+  // std::cout << "<< pos: " << counter << "\n";
   uint32_t value = 0;
 
   // We will have problems if length field is more than 32 bits. Though it's really impossible
@@ -47,6 +50,7 @@
       value <<= 8;
       value += byte;
       byte = start.ReadU8 ();
+      // Block::counter ++;
     }
   if (start.IsEnd())
     CcnbDecodingException ();
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-block.h b/helper/ccnb-parser/syntax-tree/ccnb-parser-block.h
index 1ff614b..59ccf02 100644
--- a/helper/ccnb-parser/syntax-tree/ccnb-parser-block.h
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-block.h
@@ -46,6 +46,7 @@
 class Block : public SimpleRefCount<Block>
 {
 public:
+  // static int counter;
   /**
    * \brief Parsing stream (recursively) and creating a parsed BLOCK
    * object
diff --git a/helper/ccnb-parser/syntax-tree/ccnb-parser-dtag.cc b/helper/ccnb-parser/syntax-tree/ccnb-parser-dtag.cc
index 8d9ecf7..0fdea06 100644
--- a/helper/ccnb-parser/syntax-tree/ccnb-parser-dtag.cc
+++ b/helper/ccnb-parser/syntax-tree/ccnb-parser-dtag.cc
@@ -29,7 +29,7 @@
 Dtag::Dtag (Buffer::Iterator &start, uint32_t dtag)
 {
   m_dtag = dtag;
-
+  // std::cout << m_dtag << ", position: " << Block::counter << "\n";  
   /**
    * Hack
    *
@@ -66,10 +66,21 @@
 
       m_nestedTags.push_back (Block::ParseBlock (start));
     }
+
+  // hack #3. Stop processing when last tag was <ContentObject>
+  if (m_dtag == CCN_DTAG_ContentObject && // we are in <ContentObject>
+      DynamicCast<Dtag> (m_nestedTags.back())!=0 && // last block is DTAG
+      DynamicCast<Dtag> (m_nestedTags.back())->m_dtag == CCN_DTAG_Content) 
+    {
+      return; 
+    }
+
   if (start.IsEnd ())
       throw CcnbDecodingException ();
 
   start.ReadU8 (); // read CCN_CLOSE
+  // std::cout << "closer, position = " << Block::counter << "\n";
+  // Block::counter ++;
 }
 
 }
diff --git a/helper/ccnx-decoding-helper.cc b/helper/ccnx-decoding-helper.cc
index cb38f98..52061ab 100644
--- a/helper/ccnx-decoding-helper.cc
+++ b/helper/ccnx-decoding-helper.cc
@@ -27,6 +27,8 @@
 #include "ns3/ccnb-parser-content-object-visitor.h"
 #include "ns3/ccnb-parser-block.h"
 
+#include "ns3/ccnb-parser-dtag.h"
+
 namespace ns3 {
 
 size_t
diff --git a/helper/ccnx-encoding-helper.cc b/helper/ccnx-encoding-helper.cc
index ded1627..7595bc8 100644
--- a/helper/ccnx-encoding-helper.cc
+++ b/helper/ccnx-encoding-helper.cc
@@ -185,7 +185,7 @@
 
   written += AppendBlockHeader (start, CcnbParser::CCN_DTAG_Content, CcnbParser::CCN_DTAG); // <Content>
 
-  // there is no closing tag !!!
+  // there are no closing tags !!!
   return written;
 }
 
@@ -220,7 +220,7 @@
 
   written += EstimateBlockHeader (CcnbParser::CCN_DTAG_Content); // <Content>
 
-  // there is no closing tag !!!
+  // there are no closing tags !!!
   return written;
 }
 
@@ -377,7 +377,10 @@
 size_t
 CcnxEncodingHelper::EstimateTaggedBlob (CcnbParser::ccn_dtag dtag, size_t size)
 {
-  return EstimateBlockHeader (dtag) + EstimateBlockHeader (size) + size + 1;
+  if (size>0)
+    return EstimateBlockHeader (dtag) + EstimateBlockHeader (size) + size + 1;
+  else
+    return EstimateBlockHeader (dtag) + 1;
 }
 
 
diff --git a/model/ccnx-content-object-header.cc b/model/ccnx-content-object-header.cc
index 2a248e1..e871e23 100644
--- a/model/ccnx-content-object-header.cc
+++ b/model/ccnx-content-object-header.cc
@@ -57,6 +57,7 @@
 const CcnxNameComponents&
 CcnxContentObjectHeader::GetName () const
 {
+  if (m_name==0) throw CcnxContentObjectHeaderException();
   return *m_name;
 }
 
@@ -88,10 +89,9 @@
 void
 CcnxContentObjectHeader::Print (std::ostream &os) const
 {
-  os << "<ContentObject><Name>" << *m_name << "</Name><Content>";
+  os << "<ContentObject><Name>" << GetName () << "</Name><Content>";
 }
 
-
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 
 CcnxContentObjectTail::CcnxContentObjectTail ()
@@ -102,8 +102,8 @@
 CcnxContentObjectTail::GetTypeId (void)
 {
   static TypeId tid = TypeId ("ns3::CcnxContentObjectTail")
-    .SetParent<Header> ()
-    .AddConstructor<CcnxContentObjectHeader> ()
+    .SetParent<Trailer> ()
+    .AddConstructor<CcnxContentObjectTail> ()
     ;
   return tid;
 }
@@ -130,6 +130,8 @@
 CcnxContentObjectTail::Serialize (Buffer::Iterator start) const
 {
   Buffer::Iterator i = start;
+  i.Prev (2); // Trailer interface requires us to go backwards
+  
   i.WriteU8 (0x00); // </Content>
   i.WriteU8 (0x00); // </ContentObject>
 }
@@ -138,6 +140,8 @@
 CcnxContentObjectTail::Deserialize (Buffer::Iterator start)
 {
   Buffer::Iterator i = start;
+  i.Prev (2); // Trailer interface requires us to go backwards
+
   uint8_t __attribute__ ((unused)) closing_tag_content = i.ReadU8 ();
   NS_ASSERT_MSG (closing_tag_content==0, "Should be a closing tag </Content> (0x00)");
 
diff --git a/model/ccnx-content-object-header.h b/model/ccnx-content-object-header.h
index 88887a6..f71e483 100644
--- a/model/ccnx-content-object-header.h
+++ b/model/ccnx-content-object-header.h
@@ -116,6 +116,7 @@
   virtual uint32_t Deserialize (Buffer::Iterator start);
 };
 
+class CcnxContentObjectHeaderException {};
   
 } // namespace ns3