Index: branches/HTM-DEV-0.3-dev0/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev0/source/App/TAppEncoder/TAppEncTop.cpp	(revision 497)
+++ branches/HTM-DEV-0.3-dev0/source/App/TAppEncoder/TAppEncTop.cpp	(revision 498)
@@ -1088,6 +1088,6 @@
 {   
   // Layer sets
-  vps.setVpsNumLayerSetsMinus1   ( m_vpsNumLayerSets ); 
-  vps.setVpsNumberLayerSetsMinus1( m_vpsNumLayerSets ); 
+  vps.setVpsNumLayerSetsMinus1   ( m_vpsNumLayerSets - 1 ); 
+  vps.setVpsNumberLayerSetsMinus1( vps.getVpsNumLayerSetsMinus1() ); 
     
   for (Int lsIdx = 0; lsIdx < m_vpsNumLayerSets; lsIdx++ )
Index: branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComRom.h
===================================================================
--- branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComRom.h	(revision 497)
+++ branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComRom.h	(revision 498)
@@ -162,5 +162,5 @@
 
 #ifndef ENC_DEC_TRACE
-# define ENC_DEC_TRACE 0
+# define ENC_DEC_TRACE 1
 #endif
 
Index: branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComSlice.cpp	(revision 497)
+++ branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComSlice.cpp	(revision 498)
@@ -1007,4 +1007,26 @@
   m_enableTMVPFlag                = pSrc->m_enableTMVPFlag;
   m_maxNumMergeCand               = pSrc->m_maxNumMergeCand;
+
+#if H_MV
+  // Additional slice header syntax elements 
+  m_discardableFlag            = pSrc->m_discardableFlag; 
+  m_interLayerPredEnabledFlag  = pSrc->m_interLayerPredEnabledFlag; 
+  m_numInterLayerRefPicsMinus1 = pSrc->m_numInterLayerRefPicsMinus1;
+
+  for (Int layer = 0; layer < MAX_NUM_LAYERS; layer++ )
+  {
+    m_interLayerPredLayerIdc[ layer ] = pSrc->m_interLayerPredLayerIdc[ layer ]; 
+  }
+  
+  m_interLayerSamplePredOnlyFlag = pSrc->m_interLayerSamplePredOnlyFlag;
+  m_altCollocatedIndicationFlag  = pSrc->m_altCollocatedIndicationFlag ;   
+  m_collocatedRefLayerIdx        = pSrc->m_collocatedRefLayerIdx       ;
+  m_numActiveMotionPredRefLayers = pSrc->m_numActiveMotionPredRefLayers;
+
+  for (Int layer = 0; layer < MAX_NUM_LAYER_IDS; layer++)
+  {    
+    m_interLayerPredLayerIdc[layer] = pSrc->m_interLayerPredLayerIdc[layer];
+  }
+#endif
 }
 
@@ -1577,28 +1599,4 @@
 Bool TComVPS::checkVPSExtensionSyntax()
 {
-  // check splitting flag constraint
-  if ( getSplittingFlag() )
-  {
-    // Derive dimBitOffset[j]
-    Int dimBitOffset[MAX_NUM_SCALABILITY_TYPES+1];
-    Int numScalabilityTypes = getNumScalabilityTypes();
-    dimBitOffset[0] = 0;
-
-    for (Int type = 1; type <= numScalabilityTypes; type++ )
-    {
-      dimBitOffset[ type ] = 0;
-      for (Int dimIdx = 0; dimIdx <= type - 1; dimIdx++)
-        dimBitOffset[ type ] += ( getDimensionIdLen( dimIdx ) );
-    }
-
-    for (Int type = 0; type < getNumScalabilityTypes(); type++ )
-    {
-      for( Int layer = 1; layer < getMaxLayers(); layer++ )
-      {
-        assert( getDimensionId( layer, type ) == ( ( getLayerIdInNuh( layer ) & ( (1 << dimBitOffset[ type + 1 ] ) - 1) ) >> dimBitOffset[ type ] ) );
-      }; 
-  };
-  }
-
   for( Int layer = 1; layer < getMaxLayers(); layer++ )
   {
@@ -1627,6 +1625,4 @@
   return scalIdx; 
 }
-
-
 
 Void TComVPS::setScalabilityMask( UInt val )
@@ -1754,4 +1750,43 @@
 }
 
+
+Int TComVPS::xGetDimBitOffset( Int j )
+{
+  Int dimBitOffset = 0; 
+  if ( getSplittingFlag() && j == getNumScalabilityTypes() )
+  {
+     dimBitOffset = 6; 
+  }
+  else
+  {
+    for (Int dimIdx = 0; dimIdx <= j-1; dimIdx++)
+    {
+      dimBitOffset += getDimensionIdLen( dimIdx ); 
+    }
+  }
+  return dimBitOffset; 
+}
+
+Int TComVPS::inferDimensionId( Int i, Int j )
+{
+    return ( ( getLayerIdInNuh( i ) & ( (1 << xGetDimBitOffset( j + 1 ) ) - 1) ) >> xGetDimBitOffset( j ) ); 
+}
+
+Int TComVPS::inferLastDimsionIdLen()
+{
+  return ( 5 - xGetDimBitOffset( getNumScalabilityTypes() - 1 ) ); 
+}
+
+Int TComVPS::getNumLayersInIdList( Int lsIdx )
+{
+  assert( lsIdx >= 0 ); 
+  assert( lsIdx <= getVpsNumLayerSetsMinus1() ); 
+  Int numLayersInIdList = 0; 
+  for (Int layerId = 0; layerId < getVpsMaxLayerId(); layerId++ )
+  {
+    numLayersInIdList += ( getLayerIdIncludedFlag( lsIdx, layerId ) ); 
+  }
+  return numLayersInIdList;
+}
 #endif // H_MV
 
@@ -2436,4 +2471,56 @@
 }
 
+Int TComSlice::getNumActiveRefLayerPics()
+{
+  Int numActiveRefLayerPics; 
+
+  if( getLayerId() == 0 || getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) ==  0 || !getInterLayerPredEnabledFlag() )
+  {
+    numActiveRefLayerPics = 0; 
+  }
+  else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) == 1 )
+  {
+    numActiveRefLayerPics = 1; 
+  }
+  else
+  {
+    numActiveRefLayerPics = getNumInterLayerRefPicsMinus1() + 1; 
+  }
+  return numActiveRefLayerPics;
+}
+
+Int TComSlice::getRefPicLayerId( Int i )
+{
+  return getVPS()->getRefLayerId( getLayerIdInVps(), getInterLayerPredLayerIdc( i ) );
+}
+
+Void TComSlice::setActiveMotionPredRefLayers()
+{
+  Int j = 0; 
+  for( Int i = 0; i < getNumActiveRefLayerPics(); i++)
+  {
+    if( getVPS()->getMotionPredEnabledFlag( getLayerIdInVps(), getInterLayerPredLayerIdc( i ))  )
+    {
+      m_activeMotionPredRefLayerId[ j++ ] = getVPS()->getRefLayerId( getLayerIdInVps(), i ); 
+    }
+  }
+  m_numActiveMotionPredRefLayers = j;
+
+  // Consider incorporating bitstream conformance tests on derived variables here.
+}
+
+Bool TComSlice::getInterRefEnabledInRPLFlag()
+{
+  Bool interRefEnabledInRPLFlag; 
+  if ( getVPS()->getNumSamplePredRefLayers( getLayerIdInVps() ) > 0 && getNumActiveRefLayerPics() > 0 )
+  {
+    interRefEnabledInRPLFlag = !getInterLayerSamplePredOnlyFlag(); 
+  }
+  else
+  {
+    interRefEnabledInRPLFlag = 1; 
+  }
+  return interRefEnabledInRPLFlag;
+}
 #endif
 /** get scaling matrix from RefMatrixID
Index: branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComSlice.h	(revision 497)
+++ branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComSlice.h	(revision 498)
@@ -561,5 +561,6 @@
 #endif
 
-  Int         xCeilLog2( Int val );
+  Int         xCeilLog2       ( Int val );
+  Int         xGetDimBitOffset( Int j );
 
 
@@ -730,22 +731,16 @@
   Int     scalTypeToScalIdx   ( ScalabilityType scalType );
 
-
   Int     getProfileLevelTierIdxLen() { return xCeilLog2( getVpsNumProfileTierLevelMinus1() + 1 ); };       
-  Int     getNumLayersInIdList              ( Int lsIdx )
-  {
-    assert( lsIdx >= 0 ); 
-    assert( lsIdx <= getVpsNumLayerSetsMinus1() ); 
-    Int numLayersInIdList = 0; 
-    for (Int layerId = 0; layerId < getVpsMaxLayerId(); layerId++ )
-    {
-      numLayersInIdList += ( getLayerIdIncludedFlag( lsIdx, layerId ) ); 
-    }
-    return numLayersInIdList; 
-  }; 
+  Int     getNumLayersInIdList              ( Int lsIdx );; 
+
+  // inference
+  Int     inferDimensionId     ( Int i, Int j );
+  Int     inferLastDimsionIdLen();
+
 #if H_3D  
   Void    initViewIndex(); 
   Int     getViewIndex    ( Int layerIdInVps )                             { return m_viewIndex[ layerIdInVps ]; }    
   Int     getDepthId      ( Int layerIdInVps )                             { return getScalabilityId( layerIdInVps, DEPTH_ID ); }
-  Int     getLayerIdInNuh( Int viewIndex, Bool depthFlag );  
+  Int     getLayerIdInNuh( Int viewIndex, Bool depthFlag );   
 #endif  
 #endif
@@ -1911,66 +1906,18 @@
 
 // Additional variables derived in slice header semantics 
-
 Int  getNumInterLayerRefPicsMinus1Len( ) { return xCeilLog2(  getVPS()->getNumDirectRefLayers( getLayerIdInVps() )); }
 Int  getInterLayerPredLayerIdcLen    ( ) { return xCeilLog2(  getVPS()->getNumDirectRefLayers( getLayerIdInVps() )); }
 
-Int  getNumActiveRefLayerPics( )
-{
-  Int numActiveRefLayerPics; 
-
-  if( getLayerId() == 0 || getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) ==  0 || !getInterLayerPredEnabledFlag() )
-  {
-    numActiveRefLayerPics = 0; 
-  }
-  else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) == 1 )
-  {
-    numActiveRefLayerPics = 1; 
-  }
-  else
-  {
-    numActiveRefLayerPics = getNumInterLayerRefPicsMinus1() + 1; 
-  }
-  return numActiveRefLayerPics; 
-}
-
-Int getRefPicLayerId( Int i )
-{  
-  return getVPS()->getRefLayerId( getLayerIdInVps(), getInterLayerPredLayerIdc( i ) );
-}
-
-Void setActiveMotionPredRefLayers( )
-{
-  Int j = 0; 
-  for( Int i = 0; i < getNumActiveRefLayerPics(); i++)
-  {
-    if( getVPS()->getMotionPredEnabledFlag( getLayerIdInVps(), getInterLayerPredLayerIdc( i ))  )
-    {
-      m_activeMotionPredRefLayerId[ j++ ] = getVPS()->getRefLayerId( getLayerIdInVps(), i ); 
-    }
-  }
-  m_numActiveMotionPredRefLayers = j;
-
-  // Consider incorporating bitstream conformance tests on derived variables here. 
-}
-
-Int  getActiveMotionPredRefLayerId( Int i ) { return m_activeMotionPredRefLayerId[i]; } 
-Int  getNumActiveMotionPredRefLayers(  ) { return m_numActiveMotionPredRefLayers; } 
-
-Bool getInterRefEnabledInRPLFlag( ) 
-{
-  Bool interRefEnabledInRPLFlag; 
-  if ( getVPS()->getNumSamplePredRefLayers( getLayerIdInVps() ) > 0 && getNumActiveRefLayerPics() > 0 )
-  {
-    interRefEnabledInRPLFlag = !getInterLayerSamplePredOnlyFlag(); 
-  }
-  else
-  {
-    interRefEnabledInRPLFlag = 1; 
-  }
-  return interRefEnabledInRPLFlag; 
-}
-
-Void setRefPicSetInterLayer( std::vector<TComPic*>* m_refPicSetInterLayer );
-
+Int  getNumActiveRefLayerPics( );
+Int  getRefPicLayerId               ( Int i );
+
+Void setActiveMotionPredRefLayers   ( );
+
+Int  getNumActiveMotionPredRefLayers(  )      { return m_numActiveMotionPredRefLayers; } 
+Int  getActiveMotionPredRefLayerId  ( Int i ) { return m_activeMotionPredRefLayerId[i]; } 
+
+Bool getInterRefEnabledInRPLFlag( );
+
+Void     setRefPicSetInterLayer       ( std::vector<TComPic*>* m_refPicSetInterLayer );
 TComPic* getPicFromRefPicSetInterLayer( Int layerId );
 
Index: branches/HTM-DEV-0.3-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 497)
+++ branches/HTM-DEV-0.3-dev0/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 498)
@@ -912,12 +912,16 @@
     for( Int sIdx = 0; sIdx < pcVPS->getNumScalabilityTypes( ) - ( pcVPS->getSplittingFlag() ? 1 : 0 ); sIdx++ )
     {
-        READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" );       pcVPS->setDimensionIdLen( sIdx, uiCode + 1 );
-    }
-        
+        READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" );       pcVPS->setDimensionIdLen( sIdx, uiCode + 1 );        
+    }
+     
+    if ( pcVPS->getSplittingFlag() )
+    {
+      pcVPS->setDimensionIdLen( pcVPS->getNumScalabilityTypes( ) - 1, pcVPS->inferLastDimsionIdLen() );       
+    }    
+
     READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" );           pcVPS->setVpsNuhLayerIdPresentFlag( uiCode == 1 ? true : false );
 
     for( Int i = 0; i <= pcVPS->getMaxLayers() - 1; i++ )
     {
-       
       if ( pcVPS->getVpsNuhLayerIdPresentFlag() && ( i > 0 ) )
       {
@@ -928,15 +932,20 @@
         pcVPS->setLayerIdInNuh( i, i );; 
       } 
-      
+
       pcVPS->setLayerIdInVps( pcVPS->getLayerIdInNuh( i ), i ); 
 
-      if ( !pcVPS->getSplittingFlag() )
-      {    
-        for( Int j = 0; j < pcVPS->getNumScalabilityTypes() ; j++ ) 
-        {
+      for( Int j = 0; j < pcVPS->getNumScalabilityTypes() ; j++ ) 
+      {
+        if ( !pcVPS->getSplittingFlag() )
+        {    
           READ_CODE( pcVPS->getDimensionIdLen( j ), uiCode, "dimension_id[i][j]" );  pcVPS->setDimensionId( i, j, uiCode );
         }
-      }
-    }
+        else
+        {
+          pcVPS->setDimensionId( i, j, pcVPS->inferDimensionId( i, j)  );
+        }
+      }
+    }
+    
 
     for( Int i = 1; i <= pcVPS->getMaxLayers() - 1; i++ )
@@ -979,5 +988,5 @@
     {
       READ_CODE( 10, uiCode, "num_add_output_layer_sets_minus1"      ); pcVPS->setNumAddOutputLayerSetsMinus1( uiCode );
-      numOutputLayerSets += pcVPS->getNumAddOutputLayerSetsMinus1( ); 
+      numOutputLayerSets += ( pcVPS->getNumAddOutputLayerSetsMinus1( ) + 1); 
     }
 
Index: branches/HTM-DEV-0.3-dev0/source/Lib/TLibDecoder/TDecSlice.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev0/source/Lib/TLibDecoder/TDecSlice.cpp	(revision 497)
+++ branches/HTM-DEV-0.3-dev0/source/Lib/TLibDecoder/TDecSlice.cpp	(revision 498)
@@ -123,4 +123,9 @@
   DTRACE_CABAC_T( "\tPOC: " );
   DTRACE_CABAC_V( rpcPic->getPOC() );
+#if H_MV
+  DTRACE_CABAC_T( "\tLayer: " );
+  DTRACE_CABAC_V( rpcPic->getLayerId()  );
+#endif
+
   DTRACE_CABAC_T( "\n" );
 
Index: branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 497)
+++ branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 498)
@@ -663,4 +663,5 @@
     // Operation point set
     for( UInt i = 0; i <= pcVPS->getVpsMaxLayerId(); i ++ )
+    {
 #else
   assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 );
@@ -673,8 +674,8 @@
     // Operation point set
     for( UInt i = 0; i <= pcVPS->getMaxNuhReservedZeroLayerId(); i ++ )
-#endif
     {
       // Only applicable for version 1
       pcVPS->setLayerIdIncludedFlag( true, opsIdx, i );
+#endif
       WRITE_FLAG( pcVPS->getLayerIdIncludedFlag( opsIdx, i ) ? 1 : 0, "layer_id_included_flag[opsIdx][i]" );
     }
@@ -731,4 +732,10 @@
     WRITE_CODE( pcVPS->getDimensionIdLen( sIdx ) - 1 , 3,    "dimension_id_len_minus1[j]");    
   }
+
+  if ( pcVPS->getSplittingFlag() )
+  { // Ignore old dimension id length
+    pcVPS->setDimensionIdLen( pcVPS->getNumScalabilityTypes( ) - 1 ,pcVPS->inferLastDimsionIdLen() );       
+  }    
+
 
   WRITE_FLAG( pcVPS->getVpsNuhLayerIdPresentFlag() ? 1 : 0,  "vps_nuh_layer_id_present_flag");
@@ -746,10 +753,14 @@
 
     assert(  pcVPS->getLayerIdInVps( pcVPS->getLayerIdInNuh( i ) ) == i ); 
-      
-    if ( !pcVPS->getSplittingFlag() )
-    {    
-      for( Int j = 0; j < pcVPS->getNumScalabilityTypes() ; j++ )
-      {      
+
+    for( Int j = 0; j < pcVPS->getNumScalabilityTypes() ; j++ )
+    {      
+      if ( !pcVPS->getSplittingFlag() )
+      {    
         WRITE_CODE( pcVPS->getDimensionId( i, j ), pcVPS->getDimensionIdLen( j ), "dimension_id[i][j]");      
+      }
+      else
+      {
+        assert( pcVPS->getDimensionId( i, j ) ==  pcVPS->inferDimensionId( i, j )  );
       }
     }
@@ -789,5 +800,5 @@
   {
     WRITE_CODE( pcVPS->getNumAddOutputLayerSetsMinus1( )    , 10,    "num_add_output_layer_sets_minus1"      );
-    numOutputLayerSets += pcVPS->getNumAddOutputLayerSetsMinus1( ); 
+    numOutputLayerSets += ( pcVPS->getNumAddOutputLayerSetsMinus1( ) + 1 ); 
   }
 
Index: branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncCfg.h	(revision 497)
+++ branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncCfg.h	(revision 498)
@@ -409,4 +409,5 @@
   , m_viewIndex(-1)
   , m_isDepth(false)
+  , m_bUseVSO(false)
 #endif
 #endif
Index: branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 497)
+++ branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 498)
@@ -1301,4 +1301,8 @@
   DTRACE_CABAC_T( "\tPOC: " );
   DTRACE_CABAC_V( rpcPic->getPOC() );
+#if H_MV
+  DTRACE_CABAC_T( "\tLayer: " );
+  DTRACE_CABAC_V( rpcPic->getLayerId()  );
+#endif
   DTRACE_CABAC_T( "\n" );
 #if ENC_DEC_TRACE
