Index: /branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 1042)
+++ /branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 1043)
@@ -1263,9 +1263,9 @@
   vps->setNuhLayerIdPresentFlag(false);
   vps->setLayerIdInNuh(0, 0);
-  vps->setLayerIdInVps(0, 0);
+  vps->setLayerIdxInVps(0, 0);
   for(i = 1; i < vps->getMaxLayers(); i++)
   {
     vps->setLayerIdInNuh(i, i);
-    vps->setLayerIdInVps(vps->getLayerIdInNuh(i), i);
+    vps->setLayerIdxInVps(vps->getLayerIdInNuh(i), i);
     vps->setDimensionId(i, 0, i);
   }
@@ -1529,10 +1529,11 @@
   for (UInt layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
   {
-    vps->setNumDirectRefLayers(layerCtr, m_acTEncTop[layerCtr].getNumDirectRefLayers());
+    UInt layerId = vps->getLayerIdInNuh(layerCtr);
+    vps->setNumDirectRefLayers(layerId, m_acTEncTop[layerCtr].getNumDirectRefLayers());
     maxDirectRefLayers = max<UInt>(maxDirectRefLayers, vps->getNumDirectRefLayers(layerCtr));
 
     for (i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++)
     {
-      vps->setRefLayerId(layerCtr, i, m_acTEncTop[layerCtr].getRefLayerId(i));
+      vps->setRefLayerId(layerId, i, m_acTEncTop[layerCtr].getRefLayerId(i));
     }
     // Set direct dependency flag
@@ -1544,5 +1545,5 @@
     for (i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++)
     {
-      vps->setDirectDependencyFlag(layerCtr, vps->getLayerIdInVps(m_acTEncTop[layerCtr].getRefLayerId(i)), true);
+      vps->setDirectDependencyFlag(layerCtr, vps->getLayerIdxInVps(m_acTEncTop[layerCtr].getRefLayerId(i)), true);
     }
     // prediction indications
@@ -1739,5 +1740,5 @@
     for(Int j = 0; j < numLayerInLayerSet; j++)
     {
-      Int layerIdxInVps = vps->getLayerIdInVps( vps->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, j) );
+      Int layerIdxInVps = vps->getLayerIdxInVps( vps->getLayerSetLayerIdList(layerSetIdxForOutputLayerSet, j) );
       if( vps->getNecessaryLayerFlag(i, j) )
       {
@@ -1947,5 +1948,5 @@
                 // Only for the default partition
                 Int nuhlayerId = vps->getLayerSetLayerIdList( lsIdx, k);
-                Int layerIdxInVps = vps->getLayerIdInVps( nuhlayerId );
+                Int layerIdxInVps = vps->getLayerIdxInVps( nuhlayerId );
                 vps->setBspHrdIdx(h, i, t, j, k, layerIdxInVps + vps->getNumHrdParameters());
 
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComPic.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComPic.h	(revision 1042)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComPic.h	(revision 1043)
@@ -198,6 +198,7 @@
 
 #if SVC_EXTENSION
-  Void          setLayerId (UInt layerId) { m_layerId = layerId; }
+  Void          setLayerId (UInt layerId)   { m_layerId = layerId; }
   UInt          getLayerId ()               { return m_layerId; }
+  UInt          getLayerIdx ()              { return this->getSlice(0)->getVPS()->getLayerIdxInVps(m_layerId); }
   Bool          isSpatialEnhLayer(UInt refLayerIdc)             { return m_bSpatialEnhLayer[refLayerIdc]; }
   Void          setSpatialEnhLayerFlag (UInt refLayerIdc, Bool b) { m_bSpatialEnhLayer[refLayerIdc] = b; }
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 1042)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 1043)
@@ -2083,5 +2083,5 @@
 
   m_numScalabilityTypes = 0;
-  ::memset(m_layerIdInVps, 0, sizeof(m_layerIdInVps));
+  ::memset(m_layerIdxInVps, 0, sizeof(m_layerIdxInVps));
 #endif
 #if VPS_EXTN_PROFILE_INFO
@@ -3485,9 +3485,9 @@
       for( UInt j = 0; j < m_numPredictedLayers[iNuhLId]; j++ )
       {
-        if( !countedLayerIdxFlag[m_layerIdInVps[iNuhLId]] )
+        if( !countedLayerIdxFlag[m_layerIdxInVps[iNuhLId]] )
         {
           m_treePartitionLayerIdList[numIndependentLayers][m_numLayersInTreePartition[numIndependentLayers]] = m_predictedLayerId[iNuhLId][j];
           m_numLayersInTreePartition[numIndependentLayers] = m_numLayersInTreePartition[numIndependentLayers] + 1;
-          countedLayerIdxFlag[m_layerIdInVps[m_predictedLayerId[iNuhLId][j]]] = true;
+          countedLayerIdxFlag[m_layerIdxInVps[m_predictedLayerId[iNuhLId][j]]] = true;
         }
       }
@@ -3658,5 +3658,5 @@
     for(Int i = 0; i < this->getNumLayersInIdList( lsIdx ); i++)
     {
-      Int layerIdxInVps = this->getLayerIdInVps( this->getLayerSetLayerIdList(lsIdx, i) );
+      Int layerIdxInVps = this->getLayerIdxInVps( this->getLayerSetLayerIdList(lsIdx, i) );
       Int repFormatIdx  = this->getVpsRepFormatIdx( layerIdxInVps );
       RepFormat* repFormat = this->getVpsRepFormat( repFormatIdx );
@@ -3872,5 +3872,5 @@
     for(Int k = 0; k < getNumLayersInIdList(lsIdx); k++ ) {
       Int  lId = getLayerSetLayerIdList(lsIdx, k);
-      maxSLMinus1 = std::max(maxSLMinus1, getMaxTSLayersMinus1(getLayerIdInVps(lId)));
+      maxSLMinus1 = std::max(maxSLMinus1, getMaxTSLayersMinus1(getLayerIdxInVps(lId)));
     }
     setMaxSLayersInLayerSetMinus1(lsIdx,maxSLMinus1);
@@ -3941,5 +3941,5 @@
   else
   {
-    retVal = vps->getVpsRepFormat(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(vps->getLayerIdInVps(layerId)))->getPicWidthVpsInLumaSamples();
+    retVal = vps->getVpsRepFormat(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(vps->getLayerIdxInVps(layerId)))->getPicWidthVpsInLumaSamples();
   }
 #else
@@ -3950,5 +3950,5 @@
   else
   {
-    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(vps->getLayerIdInVps(layerId)) )->getPicWidthVpsInLumaSamples();
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(vps->getLayerIdxInVps(layerId)) )->getPicWidthVpsInLumaSamples();
   }
 #endif
@@ -3984,5 +3984,5 @@
   else
   {
-    retVal = vps->getVpsRepFormat(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(vps->getLayerIdInVps(layerId)))->getPicHeightVpsInLumaSamples();
+    retVal = vps->getVpsRepFormat(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(vps->getLayerIdxInVps(layerId)))->getPicHeightVpsInLumaSamples();
   }
 #else
@@ -3993,5 +3993,5 @@
   else
   {
-    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(vps->getLayerIdInVps(layerId)) )->getPicHeightVpsInLumaSamples();
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(vps->getLayerIdxInVps(layerId)) )->getPicHeightVpsInLumaSamples();
   }
 #endif
@@ -4036,5 +4036,5 @@
   else
   {
-    retVal = vps->getVpsRepFormat(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(vps->getLayerIdInVps(layerId)))->getChromaFormatVpsIdc();
+    retVal = vps->getVpsRepFormat(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(vps->getLayerIdxInVps(layerId)))->getChromaFormatVpsIdc();
   }
 #else
@@ -4045,5 +4045,5 @@
   else
   {
-    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(vps->getLayerIdInVps(layerId)) )->getChromaFormatVpsIdc();
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(vps->getLayerIdxInVps(layerId)) )->getChromaFormatVpsIdc();
   }
 #endif
@@ -4078,5 +4078,5 @@
   else
   {
-    retVal = vps->getVpsRepFormat(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(vps->getLayerIdInVps(layerId)))->getBitDepthVpsLuma();
+    retVal = vps->getVpsRepFormat(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(vps->getLayerIdxInVps(layerId)))->getBitDepthVpsLuma();
   }
 #else
@@ -4087,5 +4087,5 @@
   else
   {
-    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(vps->getLayerIdInVps(layerId)) )->getBitDepthVpsLuma();
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(vps->getLayerIdxInVps(layerId)) )->getBitDepthVpsLuma();
   }
 #endif
@@ -4120,5 +4120,5 @@
   else
   {
-    retVal = vps->getVpsRepFormat(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(vps->getLayerIdInVps(layerId)))->getBitDepthVpsChroma();
+    retVal = vps->getVpsRepFormat(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(vps->getLayerIdxInVps(layerId)))->getBitDepthVpsChroma();
   }
 #else
@@ -4129,5 +4129,5 @@
   else
   {
-    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(vps->getLayerIdInVps(layerId)) )->getBitDepthVpsChroma();
+    retVal = vps->getVpsRepFormat( vps->getVpsRepFormatIdx(vps->getLayerIdxInVps(layerId)) )->getBitDepthVpsChroma();
   }
 #endif
@@ -4173,5 +4173,5 @@
   else
   {
-    return vps->getVpsRepFormat(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(vps->getLayerIdInVps(layerId)))->getConformanceWindowVps();
+    return vps->getVpsRepFormat(sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : vps->getVpsRepFormatIdx(vps->getLayerIdxInVps(layerId)))->getConformanceWindowVps();
   }
 #else
@@ -4182,5 +4182,5 @@
   else
   {
-    return vps->getVpsRepFormat( vps->getVpsRepFormatIdx(vps->getLayerIdInVps(vps->getLayerIdInVps(layerId))) )->getConformanceWindowVps();
+    return vps->getVpsRepFormat( vps->getVpsRepFormatIdx(vps->getLayerIdxInVps(vps->getLayerIdxInVps(layerId))) )->getConformanceWindowVps();
   }
 #endif
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.h	(revision 1042)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.h	(revision 1043)
@@ -676,5 +676,5 @@
   // Below are derived variables
   UInt       m_numScalabilityTypes;
-  UInt       m_layerIdInVps[MAX_VPS_LAYER_ID_PLUS1];            // Maps layer_id_in_nuh with the layer ID in the VPS
+  UInt       m_layerIdxInVps[MAX_VPS_LAYER_ID_PLUS1];            // Maps layer_id_in_nuh with the layer ID in the VPS
 #endif
 #if BITRATE_PICRATE_SIGNALLING
@@ -1098,6 +1098,6 @@
   Void   setNumScalabilityTypes(UInt x)                         { m_numScalabilityTypes = x;       }
 
-  UInt   getLayerIdInVps(Int id)                                { return m_layerIdInVps[id];       }
-  Void   setLayerIdInVps(Int id, UInt x)                        { m_layerIdInVps[id] = x;          }
+  UInt   getLayerIdxInVps(Int layerId)                          { return m_layerIdxInVps[layerId]; }
+  Void   setLayerIdxInVps(Int layerId, UInt x)                  { m_layerIdxInVps[layerId] = x;    }
 #endif
 #if BITRATE_PICRATE_SIGNALLING
@@ -1134,6 +1134,6 @@
 #if VPS_EXTN_DIRECT_REF_LAYERS
   // Direct dependency of layers
-  Bool   getDirectDependencyFlag(Int currLayerId, Int refLayerId)               { return m_directDependencyFlag[currLayerId][refLayerId]; }
-  Void   setDirectDependencyFlag(Int currLayerId, Int refLayerId, Bool x)       { m_directDependencyFlag[currLayerId][refLayerId] = x;    }
+  Bool   getDirectDependencyFlag(Int currLayerIdc, Int refLayerIdc)               { return m_directDependencyFlag[currLayerIdc][refLayerIdc]; }
+  Void   setDirectDependencyFlag(Int currLayerIdc, Int refLayerIdc, Bool x)       { m_directDependencyFlag[currLayerIdc][refLayerIdc] = x;    }
   
   UInt   getNumDirectRefLayers(Int layerId)                                     { return m_numDirectRefLayers[layerId];                   }
@@ -1396,5 +1396,5 @@
   Int    getScalabilityId(Int, ScalabilityType scalType );
 
-  Int    getViewIndex    ( Int layerIdInNuh )                       { return getScalabilityId( getLayerIdInVps(layerIdInNuh), VIEW_ORDER_INDEX  ); }    
+  Int    getViewIndex    ( Int layerIdInNuh )                       { return getScalabilityId( getLayerIdxInVps(layerIdInNuh), VIEW_ORDER_INDEX  ); }    
 
   Int    getNumViews();
Index: /branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1042)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1043)
@@ -1347,5 +1347,5 @@
 #if N0065_LAYER_POC_ALIGNMENT
 #if O0062_POC_LSB_NOT_PRESENT_FLAG
-    if( ( pcSlice->getLayerId() > 0 && !pcSlice->getVPS()->getPocLsbNotPresentFlag( pcSlice->getVPS()->getLayerIdInVps(pcSlice->getLayerId())) ) || !pcSlice->getIdrPicFlag() )
+    if( ( pcSlice->getLayerId() > 0 && !pcSlice->getVPS()->getPocLsbNotPresentFlag( pcSlice->getVPS()->getLayerIdxInVps(pcSlice->getLayerId())) ) || !pcSlice->getIdrPicFlag() )
 #else
     if( pcSlice->getLayerId() > 0 || !pcSlice->getIdrPicFlag() )
@@ -1536,8 +1536,8 @@
           if(chkAssert)
           {
-            // There may be something wrong here (layer id assumed to be layer idx?)
-            assert(rps->getNumberOfNegativePictures() <= pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , pcSlice->getLayerId() , pcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
-            assert(rps->getNumberOfPositivePictures() <= pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , pcSlice->getLayerId() , pcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)) - rps->getNumberOfNegativePictures());
-            assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii , pcSlice->getLayerId() , pcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
+            UInt layerIdx = pcSlice->getVPS()->getLayerIdxInVps(pcSlice->getLayerId());
+            assert(rps->getNumberOfNegativePictures() <= pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii, layerIdx, pcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
+            assert(rps->getNumberOfPositivePictures() <= pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii, layerIdx, pcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)) - rps->getNumberOfNegativePictures());
+            assert((rps->getNumberOfPositivePictures() + rps->getNumberOfNegativePictures() + rps->getNumberOfLongtermPictures()) <= pcSlice->getVPS()->getMaxVpsDecPicBufferingMinus1(ii, layerIdx, pcSlice->getVPS()->getMaxSLayersInLayerSetMinus1(ii)));
           }
         }
@@ -1601,9 +1601,9 @@
             {
 #if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
-              if((pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getVPS()->getLayerIdInVps(i),pcSlice->getLayerId()) >  pcSlice->getTLayer() || pcSlice->getTLayer()==0) &&
-                (pcSlice->getVPS()->getMaxTSLayersMinus1(pcSlice->getVPS()->getLayerIdInVps(i)) >=  pcSlice->getTLayer()) )
+              if((pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getVPS()->getLayerIdxInVps(i),pcSlice->getLayerId()) >  pcSlice->getTLayer() || pcSlice->getTLayer()==0) &&
+                (pcSlice->getVPS()->getMaxTSLayersMinus1(pcSlice->getVPS()->getLayerIdxInVps(i)) >=  pcSlice->getTLayer()) )
 #else 
-              if(pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getVPS()->getLayerIdInVps(i),pcSlice->getLayerId()) >  pcSlice->getTLayer() &&
-                (pcSlice->getVPS()->getMaxTSLayersMinus1(pcSlice->getVPS()->getLayerIdInVps(i)) >=  pcSlice->getTLayer()) )
+              if(pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getVPS()->getLayerIdxInVps(i),pcSlice->getLayerId()) >  pcSlice->getTLayer() &&
+                (pcSlice->getVPS()->getMaxTSLayersMinus1(pcSlice->getVPS()->getLayerIdxInVps(i)) >=  pcSlice->getTLayer()) )
 #endif 
               {          
@@ -1664,9 +1664,9 @@
       {
 #if Q0060_MAX_TID_REF_EQUAL_TO_ZERO
-        if((pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getVPS()->getLayerIdInVps(i),pcSlice->getLayerId()) >  pcSlice->getTLayer() || pcSlice->getTLayer()==0) &&
-          (pcSlice->getVPS()->getMaxTSLayersMinus1(pcSlice->getVPS()->getLayerIdInVps(i)) >=  pcSlice->getTLayer()) )
+        if((pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getVPS()->getLayerIdxInVps(i),pcSlice->getLayerId()) >  pcSlice->getTLayer() || pcSlice->getTLayer()==0) &&
+          (pcSlice->getVPS()->getMaxTSLayersMinus1(pcSlice->getVPS()->getLayerIdxInVps(i)) >=  pcSlice->getTLayer()) )
 #else 
-        if(pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getVPS()->getLayerIdInVps(i),pcSlice->getLayerId()) >  pcSlice->getTLayer() &&
-          (pcSlice->getVPS()->getMaxTSLayersMinus1(pcSlice->getVPS()->getLayerIdInVps(i)) >=  pcSlice->getTLayer()) )
+        if(pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getVPS()->getLayerIdxInVps(i),pcSlice->getLayerId()) >  pcSlice->getTLayer() &&
+          (pcSlice->getVPS()->getMaxTSLayersMinus1(pcSlice->getVPS()->getLayerIdxInVps(i)) >=  pcSlice->getTLayer()) )
 #endif 
         {          
@@ -1714,5 +1714,5 @@
       else
       {
-        format = pcSlice->getVPS()->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : pcSlice->getVPS()->getVpsRepFormatIdx( pcSlice->getVPS()->getLayerIdInVps(sps->getLayerId()) ) )->getChromaFormatVpsIdc();
+        format = pcSlice->getVPS()->getVpsRepFormat( sps->getUpdateRepFormatFlag() ? sps->getUpdateRepFormatIndex() : pcSlice->getVPS()->getVpsRepFormatIdx( pcSlice->getVPS()->getLayerIdxInVps(sps->getLayerId()) ) )->getChromaFormatVpsIdc();
 #if Q0195_REP_FORMAT_CLEANUP
         assert( (sps->getUpdateRepFormatFlag()==false && pcSlice->getVPS()->getVpsNumRepFormats()==1) || pcSlice->getVPS()->getVpsNumRepFormats() > 1 ); //conformance check
@@ -2062,5 +2062,5 @@
     }
 #if Q0142_POC_LSB_NOT_PRESENT
-    if ( pcSlice->getVPS()->getPocLsbNotPresentFlag( pcSlice->getVPS()->getLayerIdInVps(pcSlice->getLayerId()) ) && iPOClsb > 0 )
+    if ( pcSlice->getVPS()->getPocLsbNotPresentFlag( pcSlice->getVPS()->getLayerIdxInVps(pcSlice->getLayerId()) ) && iPOClsb > 0 )
     {
       assert( pcSlice->getPocResetIdc() != 2 );
@@ -2082,5 +2082,5 @@
       READ_CODE(pcSlice->getSPS()->getBitsForPOC(), uiCode,"poc_lsb_val"); pcSlice->setPocLsbVal(uiCode);
 #if Q0142_POC_LSB_NOT_PRESENT
-      if ( pcSlice->getVPS()->getPocLsbNotPresentFlag( pcSlice->getVPS()->getLayerIdInVps(pcSlice->getLayerId()) ) && pcSlice->getFullPocResetFlag() )
+      if ( pcSlice->getVPS()->getPocLsbNotPresentFlag( pcSlice->getVPS()->getLayerIdxInVps(pcSlice->getLayerId()) ) && pcSlice->getFullPocResetFlag() )
       {
         assert( pcSlice->getPocLsbVal() == 0 );
@@ -2854,5 +2854,5 @@
   READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" ); vps->setNuhLayerIdPresentFlag(uiCode ? true : false);
   vps->setLayerIdInNuh(0, 0);
-  vps->setLayerIdInVps(0, 0);
+  vps->setLayerIdxInVps(0, 0);
   for(i = 1; i < vps->getMaxLayers(); i++)
   {
@@ -2866,5 +2866,5 @@
       vps->setLayerIdInNuh(i, i);
     }
-    vps->setLayerIdInVps(vps->getLayerIdInNuh(i), i);
+    vps->setLayerIdxInVps(vps->getLayerIdInNuh(i), i);
 
     if( !vps->getSplittingFlag() )
@@ -2881,13 +2881,9 @@
 #endif
 #if VIEW_ID_RELATED_SIGNALING
-  // if ( pcVPS->getNumViews() > 1 )
-  //   However, this is a bug in the text since, view_id_len_minus1 is needed to parse view_id_val.
-  {
 #if O0109_VIEW_ID_LEN
-    READ_CODE( 4, uiCode, "view_id_len" ); vps->setViewIdLen( uiCode );
-#else
-    READ_CODE( 4, uiCode, "view_id_len_minus1" ); vps->setViewIdLenMinus1( uiCode );
-#endif
-  }
+  READ_CODE( 4, uiCode, "view_id_len" ); vps->setViewIdLen( uiCode );
+#else
+  READ_CODE( 4, uiCode, "view_id_len_minus1" ); vps->setViewIdLenMinus1( uiCode );
+#endif
 
 #if O0109_VIEW_ID_LEN
@@ -2910,6 +2906,7 @@
   vps->setNumDirectRefLayers(0, 0);
   // For other layers
-  for( Int layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
-  {
+  for( Int layerCtr = 1; layerCtr < vps->getMaxLayers(); layerCtr++)
+  {
+    UInt layerId = vps->getLayerIdInNuh(layerCtr); 
     UInt numDirectRefLayers = 0;
     for( Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
@@ -2918,9 +2915,9 @@
       if(uiCode)
       {
-        vps->setRefLayerId(layerCtr, numDirectRefLayers, refLayerCtr);
+        vps->setRefLayerId(layerId, numDirectRefLayers, vps->getLayerIdInNuh(refLayerCtr));
         numDirectRefLayers++;
       }
     }
-    vps->setNumDirectRefLayers(layerCtr, numDirectRefLayers);
+    vps->setNumDirectRefLayers(layerId, numDirectRefLayers);
   }
 #endif
@@ -3673,5 +3670,5 @@
   {
     vps->setLayerIdInNuh(i, i);
-    vps->setLayerIdInVps(vps->getLayerIdInNuh(i), i);
+    vps->setLayerIdxInVps(vps->getLayerIdInNuh(i), i);
   }
 
@@ -3868,5 +3865,5 @@
     for(Int k = 0; k < vps->getNumLayersInIdList(optLsIdx); k++ ) {
       Int  lId = vps->getLayerSetLayerIdList(optLsIdx, k);
-      maxSLMinus1 = max(maxSLMinus1, vps->getMaxTSLayersMinus1(vps->getLayerIdInVps(lId)));
+      maxSLMinus1 = max(maxSLMinus1, vps->getMaxTSLayersMinus1(vps->getLayerIdxInVps(lId)));
     }
     MaxSubLayersInLayerSetMinus1[ i ] = maxSLMinus1;
@@ -4229,5 +4226,5 @@
       {
 #if VPS_VUI_TILES_NOT_IN_USE__FLAG
-        layerIdx = vps->getLayerIdInVps(vps->getRefLayerId(vps->getLayerIdInNuh(i), j));
+        layerIdx = vps->getLayerIdxInVps(vps->getRefLayerId(vps->getLayerIdInNuh(i), j));
         if (vps->getTilesInUseFlag(i) && vps->getTilesInUseFlag(layerIdx)) {
           READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); vps->setTileBoundariesAlignedFlag(i,j,(uiCode == 1));
Index: /branches/SHM-dev/source/Lib/TLibDecoder/TDecCu.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/TDecCu.h	(revision 1042)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/TDecCu.h	(revision 1043)
@@ -103,5 +103,5 @@
  
 #if SVC_EXTENSION
-  TDecTop*   getLayerDec        ( UInt LayerId )  { return m_ppcTDecTop[LayerId]; }
+  TDecTop*   getLayerDec        ( UInt layerIdx )  { return m_ppcTDecTop[layerIdx]; }
 #endif
 protected:
Index: /branches/SHM-dev/source/Lib/TLibDecoder/TDecGop.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/TDecGop.cpp	(revision 1042)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/TDecGop.cpp	(revision 1043)
@@ -252,8 +252,8 @@
   }
 #if CONFORMANCE_BITSTREAM_MODE
-  if( this->getLayerDec(pcPic->getLayerId())->getConfModeFlag() ) 
+  if( this->getLayerDec(pcPic->getLayerIdx())->getConfModeFlag() )
   {
     // Add this reconstructed picture to the parallel buffer.
-    std::vector<TComPic> *thisLayerBuffer = (this->getLayerDec(pcPic->getLayerId()))->getConfListPic();
+    std::vector<TComPic> *thisLayerBuffer = (this->getLayerDec(pcPic->getLayerIdx()))->getConfListPic();
     thisLayerBuffer->push_back(*pcPic);
     std::sort( thisLayerBuffer->begin(), thisLayerBuffer->end(), pocCompareFunction );
Index: /branches/SHM-dev/source/Lib/TLibDecoder/TDecGop.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/TDecGop.h	(revision 1042)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/TDecGop.h	(revision 1043)
@@ -118,5 +118,5 @@
 #endif
 #if SVC_EXTENSION
-  TDecTop*   getLayerDec(UInt LayerId)  { return m_ppcTDecTop[LayerId]; }
+  TDecTop*   getLayerDec(UInt layerIdx)  { return m_ppcTDecTop[layerIdx]; }
 #endif 
 
Index: /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 1042)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 1043)
@@ -483,5 +483,5 @@
 
 #if FIX_NON_OUTPUT_LAYER
-  if( this->getLayerDec(pcPic->getLayerId())->m_isOutputLayerFlag == false )
+  if( this->getLayerDec(pcPic->getLayerIdx())->m_isOutputLayerFlag == false )
   {
     pcPic->setOutputMark( false );
@@ -764,5 +764,5 @@
 
 #if P0182_VPS_VUI_PS_FLAG
-    UInt layerIdx = activeVPS->getLayerIdInVps( m_layerId );
+    UInt layerIdx = activeVPS->getLayerIdxInVps( m_layerId );
 
     if( activeVPS->getBaseLayerPSCompatibilityFlag(layerIdx) )
@@ -788,5 +788,5 @@
 
 #if R0227_REP_FORMAT_CONSTRAINT //Conformance checking for rep format -- rep format of current picture of current layer shall never be greater rep format defined in VPS for the current layer
-  UInt layerIdx = activeVPS->getLayerIdInVps(m_apcSlicePilot->getLayerId());
+  UInt layerIdx = activeVPS->getLayerIdxInVps(m_apcSlicePilot->getLayerId());
 
   if ( activeVPS->getVpsExtensionFlag() == 1 && (m_apcSlicePilot->getLayerId() == 0 || sps->getV1CompatibleSPSFlag() == 1) )
@@ -2849,5 +2849,5 @@
 
 #if VPS_EXTN_DIRECT_REF_LAYERS
-TDecTop* TDecTop::getRefLayerDec( UInt refLayerIdc )
+TDecTop* TDecTop::getRefLayerDec( UInt refLayerIdx )
 {
   TComVPS* vps = m_parameterSetManagerDecoder.getActiveVPS();
@@ -2857,5 +2857,5 @@
   }
   
-  return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, refLayerIdc ) );
+  return (TDecTop *)getLayerDec( vps->getLayerIdxInVps( vps->getRefLayerId( m_layerId, refLayerIdx ) ) );
 }
 #endif
@@ -2897,6 +2897,5 @@
   {
     Int mIdx = 0, sIdx = 0;
-    Int iNuhLId = vps->getLayerIdInNuh(i);
-    TDecTop *decTop = (TDecTop *)getLayerDec(iNuhLId);
+    TDecTop *decTop = (TDecTop *)getLayerDec(i);
     for ( Int j = 0; j < i; j++ )
     {
@@ -2961,5 +2960,5 @@
   for ( Int j = latestDecIdx + 1; j < numTargetDecLayers; j++ )
   {
-    Int jLidx = pcSlice->getVPS()->getLayerIdInVps(targetDecLayerIdList[j]);
+    Int jLidx = pcSlice->getVPS()->getLayerIdxInVps(targetDecLayerIdList[j]);
     if ( currTid <= pcSlice->getVPS()->getMaxTidIlRefPicsPlus1(latestDecLayerId,jLidx) - 1 )
     {
@@ -3109,5 +3108,5 @@
     if( vps->getOutputLayerFlag( targetOlsIdx, i ) )
     {
-      this->getLayerDec( vps->getLayerSetLayerIdList( targetLsIdx, i ) )->m_isOutputLayerFlag = true;
+      this->getLayerDec( vps->getLayerIdxInVps( vps->getLayerSetLayerIdList( targetLsIdx, i ) ) )->m_isOutputLayerFlag = true;
     }
   }
Index: /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 1042)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 1043)
@@ -242,26 +242,26 @@
 #endif
 #if POC_RESET_IDC_DECODER
-  Int getParseIdc() { return m_parseIdc;}
-  Void        setParseIdc(Int x) { m_parseIdc = x;}
-  Void        markAllPicsAsNoCurrAu();
-
-  Int   getLastPocPeriodId() { return m_lastPocPeriodId; }
-  Void  setLastPocPeriodId(Int x)    { m_lastPocPeriodId = x; }
-
-  Int   getPrevPicOrderCnt() { return m_prevPicOrderCnt; }
-  Void  setPrevPicOrderCnt(Int const x) { m_prevPicOrderCnt = x; }
-#endif
-  UInt      getLayerId            () { return m_layerId;              }
-  Void      setLayerId            (UInt layer) { m_layerId = layer; }
-  UInt      getNumLayer           () { return m_numLayer;             }
-  Void      setNumLayer           (UInt uiNum)   { m_numLayer = uiNum;  }
-  TComList<TComPic*>*      getListPic() { return &m_cListPic; }
-  Void      setLayerDec(TDecTop **p)    { m_ppcTDecTop = p; }
-  TDecTop*  getLayerDec(UInt layer)     { return m_ppcTDecTop[layer]; }
+  Int       getParseIdc                     ()                              { return m_parseIdc;               }
+  Void      setParseIdc                     (Int x)                         { m_parseIdc = x;                  }
+  Void      markAllPicsAsNoCurrAu();
+
+  Int       getLastPocPeriodId              ()                              { return m_lastPocPeriodId;        }
+  Void      setLastPocPeriodId              (Int x)                         { m_lastPocPeriodId = x;           }
+
+  Int       getPrevPicOrderCnt              ()                              { return m_prevPicOrderCnt;        }
+  Void      setPrevPicOrderCnt              (Int const x)                   { m_prevPicOrderCnt = x;           }
+#endif
+  UInt      getLayerId                      ()                              { return m_layerId;                }
+  Void      setLayerId                      (UInt layer)                    { m_layerId = layer;               }
+  UInt      getNumLayer                     ()                              { return m_numLayer;               }
+  Void      setNumLayer                     (UInt uiNum)                    { m_numLayer = uiNum;              }
+  TComList<TComPic*>*  getListPic           ()                              { return &m_cListPic;              }
+  Void      setLayerDec                     (TDecTop **p)                   { m_ppcTDecTop = p;                }
+  TDecTop*  getLayerDec                     (UInt layerIdx)                 { return m_ppcTDecTop[layerIdx];   }
 #if R0235_SMALLEST_LAYER_ID
   Void      xDeriveSmallestLayerId(TComVPS* vps);
 #endif
 #if VPS_EXTN_DIRECT_REF_LAYERS
-  TDecTop*  getRefLayerDec(UInt refLayerIdc);
+  TDecTop*  getRefLayerDec                  (UInt refLayerIdx);
   Int       getNumDirectRefLayers           ()                              { return m_numDirectRefLayers;      }
   Void      setNumDirectRefLayers           (Int num)                       { m_numDirectRefLayers = num;       }
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 1042)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 1043)
@@ -1077,5 +1077,5 @@
 #if N0065_LAYER_POC_ALIGNMENT
 #if O0062_POC_LSB_NOT_PRESENT_FLAG
-    if( (pcSlice->getLayerId() > 0 && !pcSlice->getVPS()->getPocLsbNotPresentFlag( pcSlice->getVPS()->getLayerIdInVps(pcSlice->getLayerId())) ) || !pcSlice->getIdrPicFlag())
+    if( (pcSlice->getLayerId() > 0 && !pcSlice->getVPS()->getPocLsbNotPresentFlag( pcSlice->getVPS()->getLayerIdxInVps(pcSlice->getLayerId())) ) || !pcSlice->getIdrPicFlag())
 #else
     if( pcSlice->getLayerId() > 0 || !pcSlice->getIdrPicFlag() )
@@ -2747,5 +2747,5 @@
         for(Int k = 0; k < vps->getNumLayersInIdList(optLsIdx); k++ ) {
             Int  lId = vps->getLayerSetLayerIdList(optLsIdx, k);
-            maxSLMinus1 = max(maxSLMinus1, vps->getMaxTSLayersMinus1(vps->getLayerIdInVps(lId)));
+            maxSLMinus1 = max(maxSLMinus1, vps->getMaxTSLayersMinus1(vps->getLayerIdxInVps(lId)));
         }
         MaxSubLayersInLayerSetMinus1[ i ] = maxSLMinus1;
@@ -2957,5 +2957,5 @@
       {
 #if VPS_VUI_TILES_NOT_IN_USE__FLAG
-        layerIdx = vps->getLayerIdInVps(vps->getRefLayerId(vps->getLayerIdInNuh(i), j));
+        layerIdx = vps->getLayerIdxInVps(vps->getRefLayerId(vps->getLayerIdInNuh(i), j));
         if (vps->getTilesInUseFlag(i) && vps->getTilesInUseFlag(layerIdx)) {
           WRITE_FLAG( vps->getTileBoundariesAlignedFlag(i,j) ? 1 : 0 , "tile_boundaries_aligned_flag[i][j]" );
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 1042)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 1043)
@@ -930,6 +930,6 @@
   {
 #if REPN_FORMAT_IN_VPS
-    m_cSPS.setBitDepth    (ChannelType(channelType), m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdInVps( m_layerId ) ) )->getBitDepthVps(ChannelType(channelType))            );
-    m_cSPS.setQpBDOffset  (ChannelType(channelType), (6 * (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdInVps( m_layerId ) ) )->getBitDepthVps(ChannelType(channelType)) - 8)));
+    m_cSPS.setBitDepth    (ChannelType(channelType), m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps( m_layerId ) ) )->getBitDepthVps(ChannelType(channelType))            );
+    m_cSPS.setQpBDOffset  (ChannelType(channelType), (6 * (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps( m_layerId ) ) )->getBitDepthVps(ChannelType(channelType)) - 8)));
 #else
     m_cSPS.setBitDepth    (ChannelType(channelType), g_bitDepth[channelType]            );
@@ -1580,7 +1580,7 @@
 {
 #if O0096_REP_FORMAT_INDEX
-  RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cSPS.getUpdateRepFormatFlag() ? m_cSPS.getUpdateRepFormatIndex() : m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdInVps(m_layerId) ) );
-#else
-  RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdInVps(m_layerId) ) );
+  RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cSPS.getUpdateRepFormatFlag() ? m_cSPS.getUpdateRepFormatIndex() : m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps(m_layerId) ) );
+#else
+  RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cVPS.getLayerIdxInVps(m_layerId) ) );
 #endif
   Int bitDepthY,bitDepthC,picWidth,picHeight;
@@ -1645,5 +1645,5 @@
     if( m_cVPS.getNumRefLayers( m_layerId ) == 0 )
     {
-      UInt layerIdx = m_cVPS.getLayerIdInVps( m_layerId );
+      UInt layerIdx = m_cVPS.getLayerIdxInVps( m_layerId );
       RepFormat* repFmt = m_cVPS.getVpsRepFormat(m_cVPS.getVpsRepFormatIdx(layerIdx));
       
