Index: branches/SHM-6-dev/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/SHM-6-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 662)
+++ branches/SHM-6-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 663)
@@ -91,6 +91,5 @@
   }
 
-#if REPN_FORMAT_IN_VPS
-  vps->setRepFormatIdxPresentFlag( true );   // Could be disabled to optimize in some cases.
+#if REPN_FORMAT_IN_VPS  
   Int maxRepFormatIdx = -1;
   Int formatIdx = -1;
@@ -125,9 +124,14 @@
 
     assert( m_acLayerCfg[layer].getRepFormatIdx() != -1 && "RepFormatIdx not assigned for a layer" );
+
     vps->setVpsRepFormatIdx( layer, m_acLayerCfg[layer].getRepFormatIdx() );
+
     maxRepFormatIdx = std::max( m_acLayerCfg[layer].getRepFormatIdx(), maxRepFormatIdx );
   }
+
   assert( vps->getVpsRepFormatIdx( 0 ) == 0 );  // Base layer should point to the first one.
+
   Int* mapIdxToLayer = new Int[maxRepFormatIdx + 1];
+
   // Check that all the indices from 0 to maxRepFormatIdx are used in the VPS
   for(Int i = 0; i <= maxRepFormatIdx; i++)
@@ -145,5 +149,14 @@
     assert( layer != m_numLayers );   // One of the VPS Rep format indices not set
   }
+
   vps->setVpsNumRepFormats( maxRepFormatIdx + 1 );
+
+#if Q0195_REP_FORMAT_CLEANUP
+  // When not present, the value of rep_format_idx_present_flag is inferred to be equal to 0
+  vps->setRepFormatIdxPresentFlag( vps->getVpsNumRepFormats() > 1 ? true : false );
+#else
+  vps->setRepFormatIdxPresentFlag( true );
+#endif
+
   for(UInt idx=0; idx < vps->getVpsNumRepFormats(); idx++)
   {
Index: branches/SHM-6-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/SHM-6-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 662)
+++ branches/SHM-6-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 663)
@@ -1438,4 +1438,8 @@
   READ_UVLC( uiCode, "vps_num_rep_formats_minus1" );
   vps->setVpsNumRepFormats( uiCode + 1 );
+
+  // The value of vps_num_rep_formats_minus1 shall be in the range of 0 to 255, inclusive.
+  assert( vps->getVpsNumRepFormats() > 0 && vps->getVpsNumRepFormats() <= 256 );
+
   for(i = 0; i < vps->getVpsNumRepFormats(); i++)
   {
@@ -1454,6 +1458,8 @@
   else
   {
+    // When not present, the value of rep_format_idx_present_flag is inferred to be equal to 0
     vps->setRepFormatIdxPresentFlag( false );
   }
+
   if( vps->getRepFormatIdxPresentFlag() )
   {
Index: branches/SHM-6-dev/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/SHM-6-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 662)
+++ branches/SHM-6-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 663)
@@ -1072,6 +1072,10 @@
 
 #if REPN_FORMAT_IN_VPS
-#if Q0195_REP_FORMAT_CLEANUP
+#if Q0195_REP_FORMAT_CLEANUP  
+  // The value of vps_num_rep_formats_minus1 shall be in the range of 0 to 255, inclusive.
+  assert( vps->getVpsNumRepFormats() > 0 && vps->getVpsNumRepFormats() <= 256 );
+  
   WRITE_UVLC( vps->getVpsNumRepFormats() - 1, "vps_num_rep_formats_minus1" );
+
   for(i = 0; i < vps->getVpsNumRepFormats(); i++)
   {
@@ -1080,6 +1084,13 @@
   }
 
-  if ( vps->getVpsNumRepFormats() > 1 )
+  if( vps->getVpsNumRepFormats() > 1 )
+  {
     WRITE_FLAG( vps->getRepFormatIdxPresentFlag(), "rep_format_idx_present_flag"); 
+  }
+  else
+  {
+    // When not present, the value of rep_format_idx_present_flag is inferred to be equal to 0
+    assert( !vps->getRepFormatIdxPresentFlag() );
+  }
 
   if( vps->getRepFormatIdxPresentFlag() )
