Index: /branches/SHM-dev/source/App/TAppDecoder/TAppDecCfg.cpp
===================================================================
--- /branches/SHM-dev/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 1056)
+++ /branches/SHM-dev/source/App/TAppDecoder/TAppDecCfg.cpp	(revision 1057)
@@ -69,5 +69,5 @@
 #if SVC_EXTENSION
   string cfg_ReconFile [MAX_LAYERS];
-  Int nLayerNum;
+  Int layerNum, targetLayerId;
 #if OUTPUT_LAYER_SET_INDEX
   Int olsIdx;
@@ -103,5 +103,6 @@
 #endif
 #if FIX_CONF_MODE
-  ("LayerNum,-ls", nLayerNum, MAX_NUM_LAYER_IDS, "Number of layers to be decoded.")
+  ("TargetLayerId,-lid", targetLayerId, -1, "Target layer id")
+  ("LayerNum,-ls", layerNum, MAX_NUM_LAYER_IDS, "Target layer id") // Legacy option
 #else
   ("LayerNum,-ls", nLayerNum, 1, "Number of layers to be decoded.")
@@ -165,11 +166,15 @@
   m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str());
 #if SVC_EXTENSION
-  m_tgtLayerId = nLayerNum - 1;
-  assert( m_tgtLayerId >= 0 );
+  if( targetLayerId < 0 )
+  {
+    targetLayerId = layerNum - 1;
+  }
+
+  assert( targetLayerId >= 0 );
 #if !FIX_CONF_MODE
   assert( m_tgtLayerId < MAX_LAYERS );  // If this is wrong, it should be caught by asserts in other locations.
 #endif
 #if O0137_MAX_LAYERID
-  assert( m_tgtLayerId < MAX_NUM_LAYER_IDS );
+  assert( targetLayerId < MAX_NUM_LAYER_IDS );
 #endif
 #if OUTPUT_LAYER_SET_INDEX
@@ -207,5 +212,5 @@
 #endif
   m_commonDecoderParams.setTargetOutputLayerSetIdx( olsIdx );
-  m_commonDecoderParams.setTargetLayerId( m_tgtLayerId );
+  m_commonDecoderParams.setTargetLayerId( targetLayerId );
 #endif
 #if FIX_CONF_MODE
Index: /branches/SHM-dev/source/App/TAppDecoder/TAppDecCfg.h
===================================================================
--- /branches/SHM-dev/source/App/TAppDecoder/TAppDecCfg.h	(revision 1056)
+++ /branches/SHM-dev/source/App/TAppDecoder/TAppDecCfg.h	(revision 1057)
@@ -75,5 +75,4 @@
 
 #if SVC_EXTENSION
-  Int           m_tgtLayerId;                        ///< target layer ID
 #if AVC_BASE
   Char*         m_pchBLReconFile;                     ///< input BL reconstruction file name
@@ -118,5 +117,4 @@
 #endif
 #if SVC_EXTENSION
-  , m_tgtLayerId(0)
 #if AVC_BASE && !REPN_FORMAT_IN_VPS
   , m_iBLSourceWidth(0)
Index: /branches/SHM-dev/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- /branches/SHM-dev/source/App/TAppDecoder/TAppDecTop.cpp	(revision 1056)
+++ /branches/SHM-dev/source/App/TAppDecoder/TAppDecTop.cpp	(revision 1057)
@@ -223,5 +223,5 @@
       if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu)  ||
 #if FIX_CONF_MODE
-        (nalu.m_layerId > this->getCommonDecoderParams()->getTargetLayerId()) )
+        (nalu.m_layerId > m_commonDecoderParams.getTargetLayerId()) )
 #else
         (nalu.m_layerId > m_tgtLayerId) )
Index: /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 1056)
+++ /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 1057)
@@ -772,4 +772,5 @@
   string* cfg_ReconFile      [MAX_LAYERS];
   Double* cfg_fQP            [MAX_LAYERS];
+  Int*    cfg_layerId        [MAX_LAYERS];
 #if REPN_FORMAT_IN_VPS
   Int*    cfg_repFormatIdx  [MAX_LAYERS];
@@ -911,4 +912,5 @@
     cfg_repFormatIdx[layer] = &m_acLayerCfg[layer].m_repFormatIdx;
 #endif
+    cfg_layerId[layer]              = &m_acLayerCfg[layer].m_layerId;
     cfg_SourceWidth[layer]          = &m_acLayerCfg[layer].m_iSourceWidth;
     cfg_SourceHeight[layer]         = &m_acLayerCfg[layer].m_iSourceHeight;
@@ -1122,4 +1124,5 @@
   ("RepFormatIdx%d",                                cfg_repFormatIdx,                           -1, MAX_LAYERS, "Index to the representation format structure used from the VPS")
 #endif
+  ("LayerId%d",                                     cfg_layerId,                                -1, MAX_LAYERS,  "Layer id")
 #if VPS_EXTN_DIRECT_REF_LAYERS
   ("NumSamplePredRefLayers%d",                      cfg_numSamplePredRefLayers,                 -1, MAX_LAYERS, "Number of sample prediction reference layers")
@@ -1130,5 +1133,5 @@
   ("PredLayerIds%d",                                cfg_predLayerIdsPtr,                string(""), MAX_LAYERS, "inter-layer prediction layer IDs")
 #endif
-  ("NumLayers",                                     m_numLayers,                                             1, "Number of layers to code")
+  ("NumLayers",                                     m_numLayers,                                             1, "Number of layers to code")  
 #if Q0078_ADD_LAYER_SETS
 #if OUTPUT_LAYER_SETS_CONFIG
@@ -4601,6 +4604,6 @@
     for(Int i = 0; i < m_acLayerCfg[layerIdx].m_numSamplePredRefLayers; i++)
     {
-      xConfirmPara(m_acLayerCfg[layerIdx].m_samplePredRefLayerIds[i] > layerIdx, "Cannot reference higher layers");
-      xConfirmPara(m_acLayerCfg[layerIdx].m_samplePredRefLayerIds[i] == layerIdx, "Cannot reference the current layer itself");
+      xConfirmPara(m_acLayerCfg[layerIdx].m_samplePredRefLayerIds[i] > m_acLayerCfg[layerIdx].m_layerId, "Cannot reference higher layers");
+      xConfirmPara(m_acLayerCfg[layerIdx].m_samplePredRefLayerIds[i] == m_acLayerCfg[layerIdx].m_layerId, "Cannot reference the current layer itself");
     }
   }
@@ -4612,6 +4615,6 @@
     for(Int i = 0; i < m_acLayerCfg[layerIdx].m_numMotionPredRefLayers; i++)
     {
-      xConfirmPara(m_acLayerCfg[layerIdx].m_motionPredRefLayerIds[i] > layerIdx, "Cannot reference higher layers");
-      xConfirmPara(m_acLayerCfg[layerIdx].m_motionPredRefLayerIds[i] == layerIdx, "Cannot reference the current layer itself");
+      xConfirmPara(m_acLayerCfg[layerIdx].m_motionPredRefLayerIds[i] > m_acLayerCfg[layerIdx].m_layerId, "Cannot reference higher layers");
+      xConfirmPara(m_acLayerCfg[layerIdx].m_motionPredRefLayerIds[i] == m_acLayerCfg[layerIdx].m_layerId, "Cannot reference the current layer itself");
     }
   }
Index: /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.h	(revision 1056)
+++ /branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.h	(revision 1057)
@@ -61,4 +61,5 @@
 #if SVC_EXTENSION
   TAppEncLayerCfg m_acLayerCfg [MAX_LAYERS];
+  Int       m_layerId;
   Int       m_numLayers;                                      ///< number of layers
   Int       m_scalabilityMask[MAX_VPS_NUM_SCALABILITY_TYPES]; ///< scalability_mask
@@ -577,5 +578,5 @@
 #if SVC_EXTENSION
   Int  getNumFrameToBeEncoded()    {return m_framesToBeEncoded; }
-  Int  getNumLayer()               {return m_numLayers;        }
+  Int  getNumLayer()               {return m_numLayers;         }
   Int  getGOPSize()                {return m_iGOPSize;          }
 #if O0194_DIFFERENT_BITDEPTH_EL_BL
Index: /branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.h
===================================================================
--- /branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 1056)
+++ /branches/SHM-dev/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 1057)
@@ -30,5 +30,5 @@
   string    m_cInputFile;                                     ///< source file name
   string    m_cReconFile;                                     ///< output reconstruction file
-
+  Int       m_layerId;                                        ///< layer Id
   Int       m_iFrameRate;                                     ///< source frame-rates (Hz)
   Int       m_iSourceWidth;                                   ///< source width in pixel
@@ -209,5 +209,5 @@
   Int     getNumActiveRefLayers()     {return m_numActiveRefLayers;}
   Int*    getPredLayerIds()           {return m_predLayerIds;     }
-  Int     getPredLayerId(Int i)       {return m_predLayerIds[i];  }
+  Int     getPredLayerIdx(Int i)      {return m_predLayerIds[i];  }
 #endif
 #if RC_SHVC_HARMONIZATION
Index: /branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 1056)
+++ /branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 1057)
@@ -301,7 +301,7 @@
 #endif
     // set layer ID
-    m_acTEncTop[layer].setLayerId ( layer );
-    m_acTEncTop[layer].setNumLayer ( m_numLayers );
-    m_acTEncTop[layer].setLayerEnc(m_apcTEncTop);
+    m_acTEncTop[layer].setLayerId                                         ( m_acLayerCfg[layer].m_layerId == -1 ? layer : m_acLayerCfg[layer].m_layerId );
+    m_acTEncTop[layer].setNumLayer                                        ( m_numLayers );
+    m_acTEncTop[layer].setLayerEnc                                        ( m_apcTEncTop );
 
     //====== Coding Structure ========
@@ -354,4 +354,7 @@
     if(layer)
     {
+      UInt prevLayerIdx = m_acLayerCfg[layer].getPredLayerIdx(m_acLayerCfg[layer].getNumActiveRefLayers() - 1);
+      UInt prevLayerId  = m_acTEncTop[layer].getRefLayerId(prevLayerIdx);
+
       for(Int i = 0; i < MAX_VPS_LAYER_IDX_PLUS1; i++)
       {
@@ -363,6 +366,6 @@
         // Not included in the configuration file; assume that each layer depends on previous layer
         m_acTEncTop[layer].setNumSamplePredRefLayers                      (1);      // One sample pred ref. layer
-        m_acTEncTop[layer].setSamplePredRefLayerId                        (0, layer - 1);   // Previous layer
-        m_acTEncTop[layer].setSamplePredEnabledFlag                       (layer - 1, true);
+        m_acTEncTop[layer].setSamplePredRefLayerId                        (prevLayerIdx, prevLayerId);   // Previous layer
+        m_acTEncTop[layer].setSamplePredEnabledFlag                       (prevLayerIdx, true);
       }
       else
@@ -372,5 +375,4 @@
         {
           m_acTEncTop[layer].setSamplePredRefLayerId                      ( i, m_acLayerCfg[layer].getSamplePredRefLayerId(i));
-          m_acTEncTop[layer].setSamplePredEnabledFlag                     (m_acLayerCfg[layer].getSamplePredRefLayerId(i), true);
         }
       }
@@ -379,6 +381,6 @@
         // Not included in the configuration file; assume that each layer depends on previous layer
         m_acTEncTop[layer].setNumMotionPredRefLayers                      (1);      // One motion pred ref. layer
-        m_acTEncTop[layer].setMotionPredRefLayerId                        (0, layer - 1);   // Previous layer
-        m_acTEncTop[layer].setMotionPredEnabledFlag                       (layer - 1, true);
+        m_acTEncTop[layer].setMotionPredRefLayerId                        (prevLayerIdx, prevLayerId);   // Previous layer
+        m_acTEncTop[layer].setMotionPredEnabledFlag                       (prevLayerIdx, true);
       }
       else
@@ -388,5 +390,4 @@
         {
           m_acTEncTop[layer].setMotionPredRefLayerId                      ( i, m_acLayerCfg[layer].getMotionPredRefLayerId(i));
-          m_acTEncTop[layer].setMotionPredEnabledFlag                     (m_acLayerCfg[layer].getMotionPredRefLayerId(i), true);
         }
       }
@@ -395,13 +396,36 @@
       assert( layer < MAX_LAYERS );
 
-      for (Int i = 0; i < layer; i++)
-      {
-        if (m_acTEncTop[layer].getSamplePredEnabledFlag(i) || m_acTEncTop[layer].getMotionPredEnabledFlag(i))
+      for (Int i = 0; i < m_acLayerCfg[layer].m_layerId; i++)
+      {
+        Int refLayerId = -1;
+
+        for( Int layerIdc = 0; layerIdc < m_acTEncTop[layer].getNumSamplePredRefLayers(); layerIdc++ )
         {
-          m_acTEncTop[layer].setRefLayerId                                (numDirectRefLayers, i);
+          if( m_acLayerCfg[layer].getSamplePredRefLayerId(layerIdc) == i )
+          {
+            refLayerId = i;
+            m_acTEncTop[layer].setSamplePredEnabledFlag( numDirectRefLayers, true );
+            break;
+          }
+        }
+
+        for( Int layerIdc = 0; layerIdc < m_acTEncTop[layer].getNumMotionPredRefLayers(); layerIdc++ )
+        {
+          if( m_acLayerCfg[layer].getMotionPredRefLayerId(layerIdc) == i )
+          {
+            refLayerId = i;
+            m_acTEncTop[layer].setMotionPredEnabledFlag( numDirectRefLayers, true );
+            break;
+          }
+        }
+
+        if( refLayerId >= 0 )
+        {
+          m_acTEncTop[layer].setRefLayerId                                ( numDirectRefLayers, refLayerId );
           numDirectRefLayers++;
         }
       }
-      m_acTEncTop[layer].setNumDirectRefLayers                            (numDirectRefLayers);
+
+      m_acTEncTop[layer].setNumDirectRefLayers                            ( numDirectRefLayers );
 
       if(m_acLayerCfg[layer].getNumActiveRefLayers() == -1)
@@ -410,5 +434,5 @@
         for( Int i = 0; i < m_acTEncTop[layer].getNumActiveRefLayers(); i++ )
         {
-          m_acTEncTop[layer].setPredLayerId(i, i);
+          m_acTEncTop[layer].setPredLayerIdx(i, i);
         }
       }
@@ -418,5 +442,5 @@
         for(Int i = 0; i < m_acTEncTop[layer].getNumActiveRefLayers(); i++)
         {
-          m_acTEncTop[layer].setPredLayerId                               ( i, m_acLayerCfg[layer].getPredLayerId(i));
+          m_acTEncTop[layer].setPredLayerIdx                              ( i, m_acLayerCfg[layer].getPredLayerIdx(i));
         }
       }
@@ -1266,7 +1290,12 @@
   for(i = 1; i < vps->getMaxLayers(); i++)
   {
-    vps->setLayerIdInNuh(i, i);
+    vps->setLayerIdInNuh(i, m_acLayerCfg[i].m_layerId);    
     vps->setLayerIdxInVps(vps->getLayerIdInNuh(i), i);
     vps->setDimensionId(i, 0, i);
+
+    if( m_acLayerCfg[i].m_layerId != i )
+    {
+      vps->setNuhLayerIdPresentFlag(true);
+    }
   }
 
@@ -1296,5 +1325,5 @@
 
 #if VPS_EXTN_OP_LAYER_SETS
-  vps->setMaxLayerId(m_numLayers - 1);    // Set max-layer ID
+  vps->setMaxLayerId( m_acLayerCfg[m_numLayers - 1].m_layerId );    // Set max-layer ID
 
   vps->setVpsExtensionFlag( m_numLayers > 1 ? true : false );
@@ -1529,11 +1558,11 @@
   Bool isDefaultDirectDependencyTypeSet = false;
 #endif
-  for (UInt layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
+  for (UInt layerCtr = 1; layerCtr < vps->getMaxLayers(); layerCtr++)
   {
     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++)
+    maxDirectRefLayers = max<UInt>(maxDirectRefLayers, vps->getNumDirectRefLayers(layerId));
+
+    for (i = 0; i < vps->getNumDirectRefLayers(layerId); i++)
     {
       vps->setRefLayerId(layerId, i, m_acTEncTop[layerCtr].getRefLayerId(i));
@@ -1545,5 +1574,5 @@
       vps->setDirectDependencyFlag(layerCtr, refLayerCtr, false);
     }
-    for (i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++)
+    for (i = 0; i < vps->getNumDirectRefLayers(layerId); i++)
     {
       vps->setDirectDependencyFlag(layerCtr, vps->getLayerIdxInVps(m_acTEncTop[layerCtr].getRefLayerId(i)), true);
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComDataCU.cpp	(revision 1056)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComDataCU.cpp	(revision 1057)
@@ -3599,5 +3599,5 @@
       // It is a requirement of bitstream conformance that when the reference picture represented by the variable refIdxLX is an inter-layer reference picture, 
       // VpsInterLayerSamplePredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture
-      checkZeroMVILR &= m_pcSlice->getVPS()->isSamplePredictionType( m_layerId, refPic->getLayerId() );
+      checkZeroMVILR &= m_pcSlice->getVPS()->isSamplePredictionType( getLayerIdx(), refPic->getLayerIdx() );
     }
   }
@@ -3613,5 +3613,5 @@
       // It is a requirement of bitstream conformance that when the reference picture represented by the variable refIdxLX is an inter-layer reference picture, 
       // VpsInterLayerSamplePredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture
-      checkZeroMVILR &= m_pcSlice->getVPS()->isSamplePredictionType( m_layerId, refPic->getLayerId() );
+      checkZeroMVILR &= m_pcSlice->getVPS()->isSamplePredictionType( getLayerIdx(), refPic->getLayerIdx() );
     }
   }
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComDataCU.h	(revision 1056)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComDataCU.h	(revision 1057)
@@ -487,4 +487,5 @@
   Void          setLayerId (UInt layerId) { m_layerId = layerId; }
   UInt          getLayerId ()               { return m_layerId; }
+  UInt          getLayerIdx ()              { return m_pcSlice->getVPS()->getLayerIdxInVps(m_layerId); }
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
   Bool          isInterLayerReference(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1);
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComPic.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComPic.h	(revision 1056)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComPic.h	(revision 1057)
@@ -200,4 +200,5 @@
   Void          setLayerId (UInt layerId)   { m_layerId = layerId; }
   UInt          getLayerId ()               { return m_layerId; }
+  UInt          getLayerIdx()               { return 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/TComPrediction.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComPrediction.cpp	(revision 1056)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComPrediction.cpp	(revision 1057)
@@ -599,5 +599,5 @@
       // It is a requirement of bitstream conformance that when the reference picture represented by the variable refIdxLX is an inter-layer reference picture, 
       // VpsInterLayerSamplePredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture
-      assert( pcCU->getSlice()->getVPS()->isSamplePredictionType( pcCU->getLayerId(), refPic->getLayerId() ) );
+      assert( pcCU->getSlice()->getVPS()->isSamplePredictionType( pcCU->getLayerIdx(), refPic->getLayerIdx() ) );
 
 #if REF_IDX_ME_ZEROMV
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 1056)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 1057)
@@ -3363,9 +3363,9 @@
 #if CHANGE_NUMSUBDPB_IDX
   // For layer set 0
-  setNumSubDpbs(0, 1);
+  m_numSubDpbs[0] = 1;
   // For other layer sets
-  for( Int i = 1; i < getNumLayerSets(); i++)
-  {
-    setNumSubDpbs( i, getNumLayersInIdList( i ) );
+  for( Int i = 1; i < m_numLayerSets; i++)
+  {
+    m_numSubDpbs[i] = m_numLayerInIdList[i];
   }
 #else
@@ -3796,5 +3796,5 @@
   m_numNecessaryLayers.empty();
   // Assumed that output layer sets and variables RecursiveRefLayer are already derived
-  for( Int olsIdx = 0; olsIdx < getNumOutputLayerSets(); olsIdx++)
+  for( Int olsIdx = 0; olsIdx < m_numOutputLayerSets; olsIdx++)
   {
     deriveNecessaryLayerFlag(olsIdx);
@@ -3803,18 +3803,18 @@
 Void TComVPS::deriveNecessaryLayerFlag(Int const olsIdx)
 {
-  Int lsIdx = this->getOutputLayerSetIdx( olsIdx );
-  Int numLayersInLs = this->getNumLayersInIdList( lsIdx );
+  Int lsIdx = m_outputLayerSetIdx[olsIdx];
+  Int numLayersInLs = m_numLayerInIdList[lsIdx];
   assert( m_necessaryLayerFlag.size() == olsIdx );   // Function should be called in the correct order.
   m_necessaryLayerFlag.push_back( std::vector<Bool>( numLayersInLs, false ) ); // Initialize to false
   for( Int lsLayerIdx = 0; lsLayerIdx < numLayersInLs; lsLayerIdx++ )
   {
-    if( this->m_outputLayerFlag[olsIdx][lsLayerIdx] )
+    if( m_outputLayerFlag[olsIdx][lsLayerIdx] )
     {
       m_necessaryLayerFlag[olsIdx][lsLayerIdx] = true;
-      Int currNuhLayerId = this->m_layerSetLayerIdList[lsIdx][lsLayerIdx];
+      Int currNuhLayerId = m_layerSetLayerIdList[lsIdx][lsLayerIdx];
       for( Int rLsLayerIdx = 0; rLsLayerIdx < lsLayerIdx; rLsLayerIdx++ )
       {
-        Int refNuhLayerId = this->m_layerSetLayerIdList[lsIdx][rLsLayerIdx];
-        if( this->m_recursiveRefLayerFlag[currNuhLayerId][refNuhLayerId] )
+        Int refNuhLayerId = m_layerSetLayerIdList[lsIdx][rLsLayerIdx];
+        if( m_recursiveRefLayerFlag[currNuhLayerId][refNuhLayerId] )
         {
           m_necessaryLayerFlag[olsIdx][rLsLayerIdx] = true;
@@ -3831,11 +3831,11 @@
   NecessaryLayerFlag[ olsIdx ][ lsLayerIdx ] is equal to 1 for the value of lsLayerIdx 
   for which LayerSetLayerIdList[ OlsIdxToLsIdx[ olsIdx ] ][ lsLayerIdx ] is equal to layer_id_in_nuh[ layerIdx ]. */
-  for(Int layerIdx = this->getBaseLayerInternalFlag() ? 0 : 1; layerIdx < this->getMaxLayers(); layerIdx++)
+  for(Int layerIdx = m_baseLayerInternalFlag ? 0 : 1; layerIdx < m_uiMaxLayers; layerIdx++)
   {
     Bool layerFoundNecessaryLayerFlag = false;
-    for(Int olsIdx = 0; olsIdx < this->getNumOutputLayerSets(); olsIdx++)
-    {
-      Int lsIdx = this->getOutputLayerSetIdx( olsIdx );
-      Int currNuhLayerId = this->getLayerIdInNuh( layerIdx );
+    for(Int olsIdx = 0; olsIdx < m_numOutputLayerSets; olsIdx++)
+    {
+      Int lsIdx = m_outputLayerSetIdx[olsIdx];
+      Int currNuhLayerId = m_layerIdInNuh[layerIdx];
       std::vector<Int>::iterator iter = std::find( m_layerSetLayerIdList[lsIdx].begin(), m_layerSetLayerIdList[lsIdx].end(), currNuhLayerId );
       if( iter != m_layerSetLayerIdList[lsIdx].end() ) // Layer present in layer set
@@ -4299,6 +4299,9 @@
       pcIlpPic[refLayerIdc]->setIsLongTerm(1);
 
-      // assign PPS to IRLP to be used for reference location offsets
+      // assign PPS to ILRP to be used for reference location offsets
       pcIlpPic[refLayerIdc]->getSlice(0)->setPPS( m_pcPic->getSlice(0)->getPPS() );
+
+      // assing VPS to ILRP to be used for deriving layerIdx
+      pcIlpPic[refLayerIdc]->getSlice(0)->setVPS( m_pcPic->getSlice(0)->getVPS() );
 
 #if REF_IDX_MFM
Index: /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.h	(revision 1056)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComSlice.h	(revision 1057)
@@ -634,5 +634,5 @@
 #if NECESSARY_LAYER_FLAG
   std::vector< std::vector<Int> >     m_layerSetLayerIdList;
-  std::vector<Int>                      m_numLayerInIdList;;
+  std::vector<Int>                    m_numLayerInIdList;
 #else
   Int         m_layerSetLayerIdList[MAX_VPS_LAYER_SETS_PLUS1 + MAX_NUM_ADD_LAYER_SETS][MAX_VPS_LAYER_IDX_PLUS1];
@@ -1052,6 +1052,6 @@
   Void    setHighestLayerIdxPlus1(UInt set, UInt idx, UInt layerIdx)             { m_highestLayerIdxPlus1[set][idx] = layerIdx; }
   Void    setPredictedLayerIds();
-  UInt    getPredictedLayerId(UInt layerIdx, UInt predIdx)                       { return m_predictedLayerId[layerIdx][predIdx]; }
-  Void    setPredictedLayerId(UInt layerIdx, UInt predIdx, UInt x)               { m_predictedLayerId[layerIdx][predIdx] = x; }
+  UInt    getPredictedLayerId(UInt layerId, UInt predIdx)                        { return m_predictedLayerId[layerId][predIdx]; }
+  Void    setPredictedLayerId(UInt layerId, UInt predIdx, UInt x)                { m_predictedLayerId[layerId][predIdx] = x; }
   UInt    getNumPredictedLayers(UInt layerId)                                    { return m_numPredictedLayers[layerId]; }
   Void    setNumPredictedLayers(UInt layerId, UInt x)                            { m_numPredictedLayers[layerId] = x; }
@@ -1089,15 +1089,15 @@
   Void   setNuhLayerIdPresentFlag(Bool x)                       { m_nuhLayerIdPresentFlag = x;     }
 
-  UInt   getLayerIdInNuh(Int layerIdx)                          { return m_layerIdInNuh[layerIdx]; }
-  Void   setLayerIdInNuh(Int layerIdx, UInt x)                  { m_layerIdInNuh[layerIdx] = x;    }
-
-  UInt   getDimensionId(Int layerIdx, Int id)                      { return m_dimensionId[layerIdx][id]; }
-  Void   setDimensionId(Int layerIdx, Int id, UInt x)              { m_dimensionId[layerIdx][id] = x;    }
+  UInt   getLayerIdInNuh(Int layerIdx)                          { return m_layerIdInNuh[layerIdx];    }
+  Void   setLayerIdInNuh(Int layerIdx, UInt layerId)            { m_layerIdInNuh[layerIdx] = layerId; }
+
+  UInt   getDimensionId(Int layerIdx, Int id)                   { return m_dimensionId[layerIdx][id]; }
+  Void   setDimensionId(Int layerIdx, Int id, UInt x)           { m_dimensionId[layerIdx][id] = x;    }
 
   UInt   getNumScalabilityTypes()                               { return m_numScalabilityTypes;    }
   Void   setNumScalabilityTypes(UInt x)                         { m_numScalabilityTypes = x;       }
 
-  UInt   getLayerIdxInVps(Int layerId)                          { return m_layerIdxInVps[layerId]; }
-  Void   setLayerIdxInVps(Int layerId, UInt x)                  { m_layerIdxInVps[layerId] = x;    }
+  UInt   getLayerIdxInVps(Int layerId)                          { return m_layerIdxInVps[layerId];     }
+  Void   setLayerIdxInVps(Int layerId, UInt layerIdx)           { m_layerIdxInVps[layerId] = layerIdx; }
 #endif
 #if BITRATE_PICRATE_SIGNALLING
@@ -1134,6 +1134,6 @@
 #if VPS_EXTN_DIRECT_REF_LAYERS
   // Direct dependency of layers
-  Bool   getDirectDependencyFlag(Int currLayerIdc, Int refLayerIdc)               { return m_directDependencyFlag[currLayerIdc][refLayerIdc]; }
-  Void   setDirectDependencyFlag(Int currLayerIdc, Int refLayerIdc, Bool x)       { m_directDependencyFlag[currLayerIdc][refLayerIdc] = x;    }
+  Bool   getDirectDependencyFlag(Int currLayerIdx, Int refLayerIdx)             { return m_directDependencyFlag[currLayerIdx][refLayerIdx]; }
+  Void   setDirectDependencyFlag(Int currLayerIdx, Int refLayerIdx, Bool x)     { m_directDependencyFlag[currLayerIdx][refLayerIdx] = x;    }
   
   UInt   getNumDirectRefLayers(Int layerId)                                     { return m_numDirectRefLayers[layerId];                   }
@@ -1151,8 +1151,8 @@
   Void   setDefaultDirectDependecyType(UInt x)                                  { m_defaultDirectDependencyType = x;                      }
 #endif
-  UInt   getDirectDependencyType(Int currLayerId, Int refLayerId)               { return m_directDependencyType[currLayerId][refLayerId]; }
-  Void   setDirectDependencyType(Int currLayerId, Int refLayerId, UInt x)       { m_directDependencyType[currLayerId][refLayerId] = x;    }
-  Bool   isSamplePredictionType(Int currLayerId, Int refLayerId)                { assert(currLayerId != refLayerId); return ( ( m_directDependencyType[currLayerId][refLayerId] + 1 ) & 1 ) ? true : false; }
-  Bool   isMotionPredictionType(Int currLayerId, Int refLayerId)                { assert(currLayerId != refLayerId); return ( ( ( m_directDependencyType[currLayerId][refLayerId] + 1 ) & 2 ) >> 1 ) ? true : false; }
+  UInt   getDirectDependencyType(Int currLayerIdx, Int refLayerIdx)             { return m_directDependencyType[currLayerIdx][refLayerIdx]; }
+  Void   setDirectDependencyType(Int currLayerIdx, Int refLayerIdx, UInt x)     { m_directDependencyType[currLayerIdx][refLayerIdx] = x;    }
+  Bool   isSamplePredictionType(Int currLayerIdx, Int refLayerIdx)              { assert(currLayerIdx != refLayerIdx); return ( ( m_directDependencyType[currLayerIdx][refLayerIdx] + 1 ) & 1 ) ? true : false; }
+  Bool   isMotionPredictionType(Int currLayerIdx, Int refLayerIdx)              { assert(currLayerIdx != refLayerIdx); return ( ( ( m_directDependencyType[currLayerIdx][refLayerIdx] + 1 ) & 2 ) >> 1 ) ? true : false; }
 #endif
   UInt   getNumProfileTierLevel()                                { return m_numProfileTierLevel; }
Index: /branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1056)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1057)
@@ -3034,5 +3034,5 @@
 #endif
 #if LIST_OF_PTL
-  for(Int idx = vps->getBaseLayerInternalFlag() ? 2 : 1; idx <= vps->getNumProfileTierLevel() - 1; idx++)
+  for(Int idx = vps->getBaseLayerInternalFlag() ? 2 : 1; idx < vps->getNumProfileTierLevel(); idx++)
 #else
   for(Int idx = 1; idx <= vps->getNumProfileTierLevel() - 1; idx++)
Index: /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 1056)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 1057)
@@ -2229,5 +2229,5 @@
       if( refPic->isILR(pcSlice->getLayerId()) )
       {
-        assert( m_ppcTDecTop[m_layerId]->getMotionPredEnabledFlag(pcSlice->getVPS()->getLayerIdxInVps(refPic->getLayerId())) );
+        assert( m_ppcTDecTop[m_layerId]->getMotionPredEnabledFlag( refPic->getLayerIdx() ) );
       }
     }
@@ -3008,20 +3008,14 @@
     for(Int i = 0; i < vps->getNumOutputLayerSets(); i++)
     {
-      Bool layerSetMatchFlag = true;
+      Bool layerSetMatchFlag = false;
       Int layerSetIdx = vps->getOutputLayerSetIdx( i );
-      if( vps->getNumLayersInIdList( layerSetIdx ) == params->getTargetLayerId() + 1 )
-      {
-        for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
-        {
-          if( vps->getLayerSetLayerIdList( layerSetIdx, j ) != j )
-          {
-            layerSetMatchFlag = false;
-            break;
-          }
-        }
-      }
-      else
-      {
-        layerSetMatchFlag = false;
+
+      for(Int j = 0; j < vps->getNumLayersInIdList( layerSetIdx ); j++)
+      {
+        if( vps->getLayerSetLayerIdList( layerSetIdx, j ) == params->getTargetLayerId() )
+        {
+          layerSetMatchFlag = true;
+          break;
+        }
       }
       
Index: /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 1056)
+++ /branches/SHM-dev/source/Lib/TLibDecoder/TDecTop.h	(revision 1057)
@@ -273,21 +273,18 @@
   Void      setNumSamplePredRefLayers       (Int num)                       { m_numSamplePredRefLayers = num;   }
 
-  Int       getSamplePredRefLayerId         (Int i)                         { return m_samplePredRefLayerId[i];       }
-  Void      setSamplePredRefLayerId         (Int i, Int refLayerId)         { m_samplePredRefLayerId[i] = refLayerId; }
+  Int       getSamplePredRefLayerId         (Int layerIdc)                  { return m_samplePredRefLayerId[layerIdc];       }
+  Void      setSamplePredRefLayerId         (Int layerIdc, Int refLayerId)  { m_samplePredRefLayerId[layerIdc] = refLayerId; }
 
   Int       getNumMotionPredRefLayers       ()                              { return m_numMotionPredRefLayers;  }
   Void      setNumMotionPredRefLayers       (Int num)                       { m_numMotionPredRefLayers = num;   }
 
-  Int       getMotionPredRefLayerId         (Int i)                         { return m_motionPredRefLayerId[i];       }
-  Void      setMotionPredRefLayerId         (Int i, Int refLayerId)         { m_motionPredRefLayerId[i] = refLayerId; }
-
-  Bool      getSamplePredEnabledFlag        (Int i)                         { return m_samplePredEnabledFlag[i];  }
-  Void      setSamplePredEnabledFlag        (Int i,Bool flag)               { m_samplePredEnabledFlag[i] = flag;  }
-
-  Bool      getMotionPredEnabledFlag        (Int i)                         { return m_motionPredEnabledFlag[i];  }
-  Void      setMotionPredEnabledFlag        (Int i,Bool flag)               { m_motionPredEnabledFlag[i] = flag;  }
-
-  TDecTop*  getSamplePredRefLayerDec        ( UInt layerId );
-  TDecTop*  getMotionPredRefLayerDec        ( UInt layerId );
+  Int       getMotionPredRefLayerId         (Int layerIdc)                  { return m_motionPredRefLayerId[layerIdc];       }
+  Void      setMotionPredRefLayerId         (Int layerIdc, Int refLayerId)  { m_motionPredRefLayerId[layerIdc] = refLayerId; }
+
+  Bool      getSamplePredEnabledFlag        (Int layerIdx)                  { return m_samplePredEnabledFlag[layerIdx];  }
+  Void      setSamplePredEnabledFlag        (Int layerIdx, Bool flag)       { m_samplePredEnabledFlag[layerIdx] = flag;  }
+
+  Bool      getMotionPredEnabledFlag        (Int layerIdx)                  { return m_motionPredEnabledFlag[layerIdx];  }
+  Void      setMotionPredEnabledFlag        (Int layerIdx, Bool flag)       { m_motionPredEnabledFlag[layerIdx] = flag;  }
 
   Void      setRefLayerParams( TComVPS* vps );
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 1056)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 1057)
@@ -2170,10 +2170,10 @@
     if( !vps->getSplittingFlag() )
     {
-    for(j = 0; j < vps->getNumScalabilityTypes(); j++)
-    {
-      UInt bits = vps->getDimensionIdLen(j);
-      WRITE_CODE( vps->getDimensionId(i, j),   bits,   "dimension_id[i][j]" );
-    }
-  }
+      for(j = 0; j < vps->getNumScalabilityTypes(); j++)
+      {
+        UInt bits = vps->getDimensionIdLen(j);
+        WRITE_CODE( vps->getDimensionId(i, j),   bits,   "dimension_id[i][j]" );
+      }
+    }
   }
 #endif
@@ -2208,5 +2208,5 @@
 
 #if VPS_EXTN_DIRECT_REF_LAYERS
-  for( Int layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
+  for( Int layerCtr = 1; layerCtr < vps->getMaxLayers(); layerCtr++)
   {
     for( Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
@@ -2282,5 +2282,5 @@
   assert( vps->getNumProfileTierLevel() == vps->getPTLForExtnPtr()->size());
 #endif
-  for(Int idx = vps->getBaseLayerInternalFlag() ? 2 : 1; idx <= vps->getNumProfileTierLevel() - 1; idx++)
+  for(Int idx = vps->getBaseLayerInternalFlag() ? 2 : 1; idx < vps->getNumProfileTierLevel(); idx++)
 #else
   for(Int idx = 1; idx <= vps->getNumProfileTierLevel() - 1; idx++)
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 1056)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 1057)
@@ -391,5 +391,5 @@
 
   Int       m_numActiveRefLayers;
-  Int       m_predLayerId[MAX_VPS_LAYER_IDX_PLUS1];
+  Int       m_predLayerIdx[MAX_VPS_LAYER_IDX_PLUS1];
   Int       m_numSamplePredRefLayers;
   Int       m_samplePredRefLayerId[MAX_VPS_LAYER_IDX_PLUS1];
@@ -1119,24 +1119,24 @@
   Void      setNumActiveRefLayers           (Int num)                       { m_numActiveRefLayers = num;       }
 
-  Int       getPredLayerId                  (Int i)                         { return m_predLayerId[i];          }
-  Void      setPredLayerId                  (Int i, Int refLayerId)         { m_predLayerId[i] = refLayerId;    }
+  Int       getPredLayerIdx                 (Int lyaerIdc)                  { return m_predLayerIdx[lyaerIdc];          }
+  Void      setPredLayerIdx                 (Int lyaerIdc, Int refLayerIdx) { m_predLayerIdx[lyaerIdc] = refLayerIdx;   }
 
   Int       getNumSamplePredRefLayers       ()                              { return m_numSamplePredRefLayers;  }
   Void      setNumSamplePredRefLayers       (Int num)                       { m_numSamplePredRefLayers = num;   }
 
-  Int       getSamplePredRefLayerId         (Int i)                         { return m_samplePredRefLayerId[i];       }
-  Void      setSamplePredRefLayerId         (Int i, Int refLayerId)         { m_samplePredRefLayerId[i] = refLayerId; }
+  Int       getSamplePredRefLayerId         (Int layerIdc)                  { return m_samplePredRefLayerId[layerIdc];       }
+  Void      setSamplePredRefLayerId         (Int layerIdc, Int refLayerId)  { m_samplePredRefLayerId[layerIdc] = refLayerId; }
 
   Int       getNumMotionPredRefLayers       ()                              { return m_numMotionPredRefLayers;  }
   Void      setNumMotionPredRefLayers       (Int num)                       { m_numMotionPredRefLayers = num;   }
 
-  Int       getMotionPredRefLayerId         (Int i)                         { return m_motionPredRefLayerId[i];       }
-  Void      setMotionPredRefLayerId         (Int i, Int refLayerId)         { m_motionPredRefLayerId[i] = refLayerId; }
-
-  Bool      getSamplePredEnabledFlag        (Int i)                         { return m_samplePredEnabledFlag[i];  }
-  Void      setSamplePredEnabledFlag        (Int i,Bool flag)               { m_samplePredEnabledFlag[i] = flag;  }
-
-  Bool      getMotionPredEnabledFlag        (Int i)                         { return m_motionPredEnabledFlag[i];  }
-  Void      setMotionPredEnabledFlag        (Int i,Bool flag)               { m_motionPredEnabledFlag[i] = flag;  }
+  Int       getMotionPredRefLayerId         (Int layerIdc)                  { return m_motionPredRefLayerId[layerIdc];       }
+  Void      setMotionPredRefLayerId         (Int layerIdc, Int refLayerId)  { m_motionPredRefLayerId[layerIdc] = refLayerId; }
+
+  Bool      getSamplePredEnabledFlag        (Int layerIdx)                  { return m_samplePredEnabledFlag[layerIdx];  }
+  Void      setSamplePredEnabledFlag        (Int layerIdx, Bool flag)       { m_samplePredEnabledFlag[layerIdx] = flag;  }
+
+  Bool      getMotionPredEnabledFlag        (Int layerIdx)                  { return m_motionPredEnabledFlag[layerIdx];  }
+  Void      setMotionPredEnabledFlag        (Int layerIdx,Bool flag)        { m_motionPredEnabledFlag[layerIdx] = flag;  }
 #endif
   Int       getMaxTidIlRefPicsPlus1         ()                              { return m_maxTidIlRefPicsPlus1; }
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncCu.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncCu.h	(revision 1056)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncCu.h	(revision 1057)
@@ -182,5 +182,5 @@
 
 #if SVC_EXTENSION
-  TEncTop*   getLayerEnc(UInt LayerId)  {return m_ppcTEncTop[LayerId]; }
+  TEncTop*   getLayerEnc(UInt layerIdx)  {return m_ppcTEncTop[layerIdx]; }
 #if ENCODER_FAST_MODE
   Void  xCheckRDCostILRUni  ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt refLayerId);
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 1056)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 1057)
@@ -192,5 +192,6 @@
   if( pcTEncTop->getLayerId() )
   {
-    UInt prevLayerId = pcTEncTop->getLayerId()-1; // it should be changed
+    UInt prevLayerIdx = pcTEncTop->getPredLayerIdx( pcTEncTop->getNumActiveRefLayers() - 1);
+    UInt prevLayerId  = pcTEncTop->getRefLayerId(prevLayerIdx);
 
     m_Enc3DAsymLUTPicUpdate.create( m_pcCfg->getCGSMaxOctantDepth() , g_bitDepthLayer[CHANNEL_TYPE_LUMA][prevLayerId] , g_bitDepthLayer[CHANNEL_TYPE_CHROMA][prevLayerId] , g_bitDepthLayer[CHANNEL_TYPE_LUMA][pcTEncTop->getLayerId()] , g_bitDepthLayer[CHANNEL_TYPE_CHROMA][pcTEncTop->getLayerId()] , m_pcCfg->getCGSMaxYPartNumLog2() /*, m_pcCfg->getCGSPhaseAlignment()*/ );
@@ -1172,7 +1173,6 @@
         for (UInt i = 0; i < m_pcCfg->getNumLayer(); i++)
         {
-          Int layerId = pcSlice->getVPS()->getLayerIdInNuh(i);
-          m_ppcTEncTop[layerId]->setLayerInitializedFlag(false);
-          m_ppcTEncTop[layerId]->setFirstPicInLayerDecodedFlag(false);
+          m_ppcTEncTop[i]->setLayerInitializedFlag(false);
+          m_ppcTEncTop[i]->setFirstPicInLayerDecodedFlag(false);
         }
       }
@@ -1224,5 +1224,5 @@
 
         // infer the scaling list from the reference layer
-        pcSlice->setScalingList ( m_ppcTEncTop[refLayerId]->getScalingList() );
+        pcSlice->setScalingList ( m_ppcTEncTop[pcSlice->getVPS()->getLayerIdxInVps(refLayerId)]->getScalingList() );
       }
       else
@@ -1258,5 +1258,5 @@
 
         // infer the scaling list from the reference layer
-        pcSlice->setScalingList ( m_ppcTEncTop[refLayerId]->getScalingList() );
+        pcSlice->setScalingList ( m_ppcTEncTop[pcSlice->getVPS()->getLayerIdxInVps(refLayerId)]->getScalingList() );
       }
       else
@@ -1311,5 +1311,5 @@
         UInt refLayerId = pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc);
 #if VPS_EXTN_DIRECT_REF_LAYERS
-        TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(refLayerIdc)->getListPic();
+        TComList<TComPic*> *cListPic = m_ppcTEncTop[refLayerIdc]->getRefLayerEnc(refLayerIdc)->getListPic();
 #else
         TComList<TComPic*> *cListPic = m_ppcTEncTop[pcSlice->getVPS()->getLayerIdxInVps(m_layerId)-1]->getListPic();
@@ -1415,5 +1415,5 @@
         {
           // check for the sample prediction picture type
-          if( m_ppcTEncTop[m_layerId]->getSamplePredEnabledFlag(pcSlice->getVPS()->getLayerIdxInVps(refLayerId)))
+          if( m_ppcTEncTop[pcSlice->getVPS()->getLayerIdxInVps(m_layerId)]->getSamplePredEnabledFlag(pcSlice->getVPS()->getLayerIdxInVps(refLayerId)))
           {
 #if P0312_VERT_PHASE_ADJ
@@ -1494,5 +1494,5 @@
         if(pcSlice->getVPS()->getCrossLayerIrapAlignFlag())
         {
-          TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(0)->getListPic();
+          TComList<TComPic*> *cListPic = m_ppcTEncTop[pcSlice->getVPS()->getLayerIdxInVps(m_layerId)]->getRefLayerEnc(0)->getListPic();
           TComPic* picLayer0 = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() );
           if(picLayer0)
@@ -1536,5 +1536,5 @@
       if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_R &&
 #if SVC_EXTENSION
-        ( m_iGopSize != 1 || m_ppcTEncTop[m_layerId]->getIntraPeriod() > 1 ) )
+        ( m_iGopSize != 1 || m_ppcTEncTop[pcSlice->getVPS()->getLayerIdxInVps(m_layerId)]->getIntraPeriod() > 1 ) )
 #else
           !(m_iGopSize == 1 && pcSlice->getSliceType() == I_SLICE))
@@ -1841,5 +1841,5 @@
         for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
         {
-          if( m_ppcTEncTop[m_layerId]->getSamplePredEnabledFlag( pcSlice->getVPS()->getRefLayerId( m_layerId, pcSlice->getInterLayerPredLayerIdc(i) ) ) )
+          if( m_ppcTEncTop[pcSlice->getVPS()->getLayerIdxInVps(m_layerId)]->getSamplePredEnabledFlag( pcSlice->getInterLayerPredLayerIdc(i) ) )
           {
             foundSamplePredPicture = true;
@@ -1875,5 +1875,5 @@
         for( Int i = 0; i < pcSlice->getLayerId(); i++)
         {
-          TComList<TComPic *> *cListPic = m_ppcTEncTop[i]->getListPic();
+          TComList<TComPic *> *cListPic = m_ppcTEncTop[pcSlice->getVPS()->getLayerIdxInVps(i)]->getListPic();
           TComPic *lowerLayerPic = pcSlice->getRefPic(*cListPic, pcSlice->getPOC());
           if( lowerLayerPic && pcSlice->getVPS()->getDirectDependencyFlag(pcSlice->getLayerIdx(), i) )
@@ -1969,7 +1969,7 @@
           // It is a requirement of bitstream conformance when the collocated picture, used for temporal motion vector prediction, is an inter-layer reference picture, 
           // VpsInterLayerMotionPredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture.
-          if( refPic->isILR(m_layerId) && m_ppcTEncTop[m_layerId]->getMotionPredEnabledFlag( pcSlice->getVPS()->getLayerIdxInVps(refPic->getLayerId()) )
+          if( refPic->isILR(m_layerId) && m_ppcTEncTop[pcSlice->getVPS()->getLayerIdxInVps(m_layerId)]->getMotionPredEnabledFlag( refPic->getLayerIdx() )
 #if MFM_ENCCONSTRAINT
-            && pcSlice->getBaseColPic( *m_ppcTEncTop[refPic->getLayerId()]->getListPic() )->checkSameRefInfo() == true 
+            && pcSlice->getBaseColPic( *m_ppcTEncTop[refPic->getLayerIdx()]->getListPic() )->checkSameRefInfo() == true 
 #endif
             ) 
@@ -1991,7 +1991,7 @@
             // It is a requirement of bitstream conformance when the collocated picture, used for temporal motion vector prediction, is an inter-layer reference picture, 
             // VpsInterLayerMotionPredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture.
-            if( refPic->isILR(m_layerId) && m_ppcTEncTop[m_layerId]->getMotionPredEnabledFlag(pcSlice->getVPS()->getLayerIdxInVps( refPic->getLayerId()))
+            if( refPic->isILR(m_layerId) && m_ppcTEncTop[pcSlice->getVPS()->getLayerIdxInVps(m_layerId)]->getMotionPredEnabledFlag( refPic->getLayerIdx() )
 #if MFM_ENCCONSTRAINT
-              && pcSlice->getBaseColPic( *m_ppcTEncTop[refPic->getLayerId()]->getListPic() )->checkSameRefInfo() == true 
+              && pcSlice->getBaseColPic( *m_ppcTEncTop[refPic->getLayerIdx()]->getListPic() )->checkSameRefInfo() == true 
 #endif
               ) 
@@ -2110,5 +2110,5 @@
         // It is a requirement of bitstream conformance when the collocated picture, used for temporal motion vector prediction, is an inter-layer reference picture, 
         // VpsInterLayerMotionPredictionEnabled[ LayerIdxInVps[ currLayerId ] ][ LayerIdxInVps[ rLId ] ] shall be equal to 1, where rLId is set equal to nuh_layer_id of the inter-layer picture.
-        if( refPic->isILR(m_layerId) && !m_ppcTEncTop[m_layerId]->getMotionPredEnabledFlag(pcSlice->getVPS()->getLayerIdxInVps(refPic->getLayerId())))
+        if( refPic->isILR(m_layerId) && !m_ppcTEncTop[pcSlice->getVPS()->getLayerIdxInVps(m_layerId)]->getMotionPredEnabledFlag(refPic->getLayerIdx()) )
         {
           pcSlice->setEnableTMVPFlag(false);
@@ -2128,5 +2128,5 @@
           TComPic* refPic = pcSlice->getRefPic(refList, refIdx);
 
-          if( !refPic->isILR(m_layerId) || ( refPic->isILR(m_layerId) && m_ppcTEncTop[m_layerId]->getSamplePredEnabledFlag( pcSlice->getVPS()->getLayerIdxInVps(refPic->getLayerId())) ) )
+          if( !refPic->isILR(m_layerId) || ( refPic->isILR(m_layerId) && m_ppcTEncTop[pcSlice->getVPS()->getLayerIdxInVps(m_layerId)]->getSamplePredEnabledFlag( refPic->getLayerIdx() ) ) )
           {
             break;
@@ -2152,5 +2152,5 @@
           TComPic* refPic = pcSlice->getRefPic(refList, refIdx);
 
-          if( !refPic->isILR(m_layerId) || ( refPic->isILR(m_layerId) && m_ppcTEncTop[m_layerId]->getSamplePredEnabledFlag( pcSlice->getVPS()->getLayerIdxInVps((refPic->getLayerId())))) )
+          if( !refPic->isILR(m_layerId) || ( refPic->isILR(m_layerId) && m_ppcTEncTop[pcSlice->getVPS()->getLayerIdxInVps(m_layerId)]->getSamplePredEnabledFlag( refPic->getLayerIdx() ) ) )
           {
             break;
@@ -4664,7 +4664,6 @@
         for(Int i = 1; i < slice->getVPS()->getMaxLayers(); i++)
         {
-          UInt layerId = slice->getVPS()->getLayerIdInNuh(i);
-          Bool refreshIntervalFlag = ( pocCurr % m_ppcTEncTop[layerId]->getGOPEncoder()->getIntraRefreshInterval() == 0 );
-          Bool refreshTypeFlag     = ( m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshType() == m_ppcTEncTop[layerId]->getGOPEncoder()->getIntraRefreshType() );
+          Bool refreshIntervalFlag = ( pocCurr % m_ppcTEncTop[i]->getGOPEncoder()->getIntraRefreshInterval() == 0 );
+          Bool refreshTypeFlag     = ( m_ppcTEncTop[0]->getGOPEncoder()->getIntraRefreshType() == m_ppcTEncTop[i]->getGOPEncoder()->getIntraRefreshType() );
           if( !(refreshIntervalFlag && refreshTypeFlag) )
           {
@@ -4682,7 +4681,6 @@
       for(Int i = 1; i < slice->getVPS()->getMaxLayers() && !needReset; i++)
       {
-        UInt layerId = slice->getVPS()->getLayerIdInNuh(i);
-        Bool idrFlag = ( (m_ppcTEncTop[layerId]->getGOPEncoder()->getIntraRefreshType() == 2) 
-                        && ( pocCurr % m_ppcTEncTop[layerId]->getGOPEncoder()->getIntraRefreshInterval() == 0 )
+        Bool idrFlag = ( (m_ppcTEncTop[i]->getGOPEncoder()->getIntraRefreshType() == 2) 
+                        && ( pocCurr % m_ppcTEncTop[i]->getGOPEncoder()->getIntraRefreshInterval() == 0 )
                         );
         for(Int j = 0; j < slice->getVPS()->getMaxLayers(); j++)
@@ -4693,7 +4691,6 @@
           }
 
-          layerId = slice->getVPS()->getLayerIdInNuh(j);
-          Bool idrOtherPicFlag = ( (m_ppcTEncTop[layerId]->getGOPEncoder()->getIntraRefreshType() == 2) 
-                                  && ( pocCurr % m_ppcTEncTop[layerId]->getGOPEncoder()->getIntraRefreshInterval() == 0 )
+          Bool idrOtherPicFlag = ( (m_ppcTEncTop[j]->getGOPEncoder()->getIntraRefreshType() == 2) 
+                                  && ( pocCurr % m_ppcTEncTop[j]->getGOPEncoder()->getIntraRefreshInterval() == 0 )
                                   );
 
@@ -4739,6 +4736,5 @@
         for (UInt i = 0; i < MAX_LAYERS; i++)
         {
-          UInt layerId = slice->getVPS()->getLayerIdInNuh(i);
-          m_ppcTEncTop[layerId]->setPocDecrementedInDPBFlag(false);
+          m_ppcTEncTop[i]->setPocDecrementedInDPBFlag(false);
         }
 #endif
@@ -4828,16 +4824,18 @@
   for (UInt layerIdx = 0; layerIdx < numAffectedLayers; layerIdx++)
   {
-    if (!m_ppcTEncTop[affectedLayerList[layerIdx]]->getPocDecrementedInDPBFlag())
-    {
-      m_ppcTEncTop[affectedLayerList[layerIdx]]->setPocDecrementedInDPBFlag(true);
+    UInt lIdx = slice->getVPS()->getLayerIdxInVps(affectedLayerList[layerIdx]);
+
+    if (!m_ppcTEncTop[lIdx]->getPocDecrementedInDPBFlag())
+    {
+      m_ppcTEncTop[lIdx]->setPocDecrementedInDPBFlag(true);
 
       // Decrement value of associatedIrapPoc of the TEncGop object
-      m_ppcTEncTop[affectedLayerList[layerIdx]]->getGOPEncoder()->m_associatedIRAPPOC -= deltaPocVal;
+      m_ppcTEncTop[lIdx]->getGOPEncoder()->m_associatedIRAPPOC -= deltaPocVal;
 
       // Decrememnt the value of m_pocCRA
-      m_ppcTEncTop[affectedLayerList[layerIdx]]->getGOPEncoder()->m_pocCRA -= deltaPocVal;
-
-      TComList<TComPic*>::iterator  iterPic = m_ppcTEncTop[affectedLayerList[layerIdx]]->getListPic()->begin();
-      while (iterPic != m_ppcTEncTop[affectedLayerList[layerIdx]]->getListPic()->end())
+      m_ppcTEncTop[lIdx]->getGOPEncoder()->m_pocCRA -= deltaPocVal;
+
+      TComList<TComPic*>::iterator  iterPic = m_ppcTEncTop[lIdx]->getListPic()->begin();
+      while (iterPic != m_ppcTEncTop[lIdx]->getListPic()->end())
 #else
   // Decrement value of associatedIrapPoc of the TEncGop object
@@ -5342,10 +5340,10 @@
       {
         Int iLayerId = slice->getVPS()->getPredictedLayerId(dolLayerId, i);
-        m_ppcTEncTop[iLayerId]->setLayerInitializedFlag(false);
-        m_ppcTEncTop[iLayerId]->setFirstPicInLayerDecodedFlag(false);
+        m_ppcTEncTop[slice->getVPS()->getLayerIdxInVps(iLayerId)]->setLayerInitializedFlag(false);
+        m_ppcTEncTop[slice->getVPS()->getLayerIdxInVps(iLayerId)]->setFirstPicInLayerDecodedFlag(false);
       }
 
       // Each picture that is in the DPB and has nuh_layer_id equal to dolLayerId is marked as "unused for reference".
-      for (TComList<TComPic*>::iterator pic = m_ppcTEncTop[dolLayerId]->getListPic()->begin(); pic != m_ppcTEncTop[dolLayerId]->getListPic()->end(); pic++)
+      for (TComList<TComPic*>::iterator pic = m_ppcTEncTop[slice->getVPS()->getLayerIdxInVps(dolLayerId)]->getListPic()->begin(); pic != m_ppcTEncTop[slice->getVPS()->getLayerIdxInVps(dolLayerId)]->getListPic()->end(); pic++)
       {
         if ((*pic)->getSlice(0)->getPOC() != slice->getPOC())
@@ -5360,5 +5358,5 @@
       {
         UInt predLId = slice->getVPS()->getPredictedLayerId(dolLayerId, i);
-        for (TComList<TComPic*>::iterator pic = m_ppcTEncTop[predLId]->getListPic()->begin(); pic != m_ppcTEncTop[predLId]->getListPic()->end(); pic++)
+        for (TComList<TComPic*>::iterator pic = m_ppcTEncTop[slice->getVPS()->getLayerIdxInVps(predLId)]->getListPic()->begin(); pic != m_ppcTEncTop[slice->getVPS()->getLayerIdxInVps(predLId)]->getListPic()->end(); pic++)
         {
           if ((*pic)->getSlice(0)->getPOC() != slice->getPOC())
@@ -5381,5 +5379,5 @@
       m_noRaslOutputFlag = true;
     }
-    else if (!m_ppcTEncTop[m_layerId]->getLayerInitializedFlag())
+    else if (!m_ppcTEncTop[slice->getVPS()->getLayerIdxInVps(m_layerId)]->getLayerInitializedFlag())
     {
       Bool refLayersInitialized = true;
@@ -5387,5 +5385,5 @@
       {
         UInt refLayerId = slice->getVPS()->getRefLayerId(m_layerId, j);
-        if (!m_ppcTEncTop[refLayerId]->getLayerInitializedFlag())
+        if (!m_ppcTEncTop[slice->getVPS()->getLayerIdxInVps(refLayerId)]->getLayerInitializedFlag())
         {
           refLayersInitialized = false;
@@ -5406,11 +5404,11 @@
     if (m_layerId == 0)
     {
-      m_ppcTEncTop[m_layerId]->setLayerInitializedFlag(true);
-    }
-    else if (!m_ppcTEncTop[m_layerId]->getLayerInitializedFlag() && slice->getVPS()->getNumDirectRefLayers(m_layerId) == 0)
-    {
-      m_ppcTEncTop[m_layerId]->setLayerInitializedFlag(true);
-    }
-    else if (!m_ppcTEncTop[m_layerId]->getLayerInitializedFlag())
+      m_ppcTEncTop[slice->getVPS()->getLayerIdxInVps(m_layerId)]->setLayerInitializedFlag(true);
+    }
+    else if (!m_ppcTEncTop[slice->getVPS()->getLayerIdxInVps(m_layerId)]->getLayerInitializedFlag() && slice->getVPS()->getNumDirectRefLayers(m_layerId) == 0)
+    {
+      m_ppcTEncTop[slice->getVPS()->getLayerIdxInVps(m_layerId)]->setLayerInitializedFlag(true);
+    }
+    else if (!m_ppcTEncTop[slice->getVPS()->getLayerIdxInVps(m_layerId)]->getLayerInitializedFlag())
     {
       Bool refLayersInitialized = true;
@@ -5418,5 +5416,5 @@
       {
         UInt refLayerId = slice->getVPS()->getRefLayerId(m_layerId, j);
-        if (!m_ppcTEncTop[refLayerId]->getLayerInitializedFlag())
+        if (!m_ppcTEncTop[slice->getVPS()->getLayerIdxInVps(refLayerId)]->getLayerInitializedFlag())
         {
           refLayersInitialized = false;
@@ -5425,5 +5423,5 @@
       if (refLayersInitialized)
       {
-        m_ppcTEncTop[m_layerId]->setLayerInitializedFlag(true);
+        m_ppcTEncTop[slice->getVPS()->getLayerIdxInVps(m_layerId)]->setLayerInitializedFlag(true);
       }
     }
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 1056)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 1057)
@@ -3243,5 +3243,5 @@
         
         // motion search only for the ILRP with sample prediction type
-        if( pcPic->isILR( pcCU->getLayerId() ) && !pcCU->getSlice()->getVPS()->isSamplePredictionType( pcCU->getLayerId(), pcPic->getLayerId() ) )
+        if( pcPic->isILR( pcCU->getLayerId() ) && !pcCU->getSlice()->getVPS()->isSamplePredictionType( pcCU->getLayerIdx(), pcPic->getLayerIdx() ) )
         {
           continue;
@@ -3481,5 +3481,5 @@
 
           // motion search only for the ILRP with sample prediction type
-          if( pcPic->isILR( pcCU->getLayerId() ) && !pcCU->getSlice()->getVPS()->isSamplePredictionType( pcCU->getLayerId(), pcPic->getLayerId() ) )
+          if( pcPic->isILR( pcCU->getLayerId() ) && !pcCU->getSlice()->getVPS()->isSamplePredictionType( pcCU->getLayerIdx(), pcPic->getLayerIdx() ) )
           {
             continue;
@@ -6074,5 +6074,5 @@
 
       // ILRP has to be for the sample prediction type
-      if( refPic->isILR(pcCU->getLayerId()) && refPic->getLayerId() == refLayerId && pcCU->getSlice()->getVPS()->isSamplePredictionType( pcCU->getLayerId(), refLayerId ) )
+      if( refPic->isILR(pcCU->getLayerId()) && refPic->getLayerId() == refLayerId && pcCU->getSlice()->getVPS()->isSamplePredictionType( pcCU->getLayerIdx(), pcCU->getSlice()->getVPS()->getLayerIdxInVps(refLayerId) ) )
       {
         iRefIdxTemp = refIdx;
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 1056)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 1057)
@@ -139,12 +139,12 @@
 {
 #if JCTVC_M0259_LAMBDAREFINEMENT
-  if( slice->getLayerId() > 0 && m_ppcTEncTop[slice->getLayerId()]->getNumActiveRefLayers() && depth >= 3 && m_pcCfg->getGOPSize() == ( 1 << depth ) )
-  {
-    Int nCurLayerId = slice->getLayerId();
-    UInt prevLayerId = slice->getVPS()->getLayerIdInNuh(slice->getVPS()->getLayerIdxInVps(nCurLayerId)-1);
-
-    Double gamma = xCalEnhLambdaFactor( m_ppcTEncTop[prevLayerId]->getQP() - m_ppcTEncTop[nCurLayerId]->getQP() ,
-      1.0 * m_ppcTEncTop[nCurLayerId]->getSourceWidth() * m_ppcTEncTop[nCurLayerId]->getSourceHeight()
-      / m_ppcTEncTop[prevLayerId]->getSourceWidth() / m_ppcTEncTop[prevLayerId]->getSourceHeight() );
+  if( slice->getLayerId() > 0 && m_ppcTEncTop[slice->getLayerIdx()]->getNumActiveRefLayers() && depth >= 3 && m_pcCfg->getGOPSize() == ( 1 << depth ) )
+  {
+    Int layerIdx = slice->getLayerId();
+    UInt prevLayerIdx = m_ppcTEncTop[layerIdx]->getPredLayerIdx( m_ppcTEncTop[layerIdx]->getNumActiveRefLayers() - 1);
+
+    Double gamma = xCalEnhLambdaFactor( m_ppcTEncTop[prevLayerIdx]->getQP() - m_ppcTEncTop[layerIdx]->getQP() ,
+      1.0 * m_ppcTEncTop[layerIdx]->getSourceWidth() * m_ppcTEncTop[layerIdx]->getSourceHeight()
+      / m_ppcTEncTop[prevLayerIdx]->getSourceWidth() / m_ppcTEncTop[prevLayerIdx]->getSourceHeight() );
     dLambda *= gamma;
   }
@@ -165,5 +165,5 @@
 
 #if JCTVC_M0259_LAMBDAREFINEMENT
-    if( slice->getLayerId() > 0 && m_ppcTEncTop[slice->getLayerId()]->getNumActiveRefLayers() && m_pcCfg->getGOPSize() >= 8 && slice->isIntra() == false && depth == 0 )
+    if( slice->getLayerId() > 0 && m_ppcTEncTop[slice->getLayerIdx()]->getNumActiveRefLayers() && m_pcCfg->getGOPSize() >= 8 && slice->isIntra() == false && depth == 0 )
     {
       dLambdas[0] = dLambda * 1.1;
@@ -557,12 +557,12 @@
     if( rpcSlice->getNumILRRefIdx() > 0 )
     {
-      rpcSlice->setActiveNumILRRefIdx( m_ppcTEncTop[layerId]->getNumActiveRefLayers() );
+      rpcSlice->setActiveNumILRRefIdx( m_ppcTEncTop[rpcSlice->getVPS()->getLayerIdxInVps(layerId)]->getNumActiveRefLayers() );
       for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
       {
-        rpcSlice->setInterLayerPredLayerIdc( m_ppcTEncTop[layerId]->getPredLayerId(i), i );
+        rpcSlice->setInterLayerPredLayerIdc( m_ppcTEncTop[rpcSlice->getVPS()->getLayerIdxInVps(layerId)]->getPredLayerIdx(i), i );
       }
       rpcSlice->setInterLayerPredEnabledFlag(1);
     }
-    rpcSlice->setMFMEnabledFlag(m_ppcTEncTop[layerId]->getMFMEnabledFlag());
+    rpcSlice->setMFMEnabledFlag(m_ppcTEncTop[rpcSlice->getVPS()->getLayerIdxInVps(layerId)]->getMFMEnabledFlag());
   }
 
@@ -764,5 +764,5 @@
   }
 #if O0194_WEIGHTED_PREDICTION_CGS
-  else if( m_ppcTEncTop[pcSlice->getLayerId()]->getInterLayerWeightedPredFlag() )
+  else if( m_ppcTEncTop[pcSlice->getLayerIdx()]->getInterLayerWeightedPredFlag() )
   {
     // Calculate for the base layer to be used in EL as Inter layer reference
@@ -1137,5 +1137,5 @@
 
 #if SVC_EXTENSION
-        m_pcEntropyCoder->encodeSAOBlkParam(saoblkParam, m_ppcTEncTop[pcSlice->getLayerId()]->getSAO()->getSaoMaxOffsetQVal(), sliceEnabled, leftMergeAvail, aboveMergeAvail);
+        m_pcEntropyCoder->encodeSAOBlkParam(saoblkParam, m_ppcTEncTop[pcSlice->getLayerIdx()]->getSAO()->getSaoMaxOffsetQVal(), sliceEnabled, leftMergeAvail, aboveMergeAvail);
 #else
         m_pcEntropyCoder->encodeSAOBlkParam(saoblkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail);
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 1056)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 1057)
@@ -1533,10 +1533,10 @@
 TEncTop* TEncTop::getRefLayerEnc( UInt refLayerIdx )
 {
-  if( m_ppcTEncTop[m_layerId]->getNumDirectRefLayers() <= 0 )
+  if( m_ppcTEncTop[m_cVPS.getLayerIdxInVps(m_layerId)]->getNumDirectRefLayers() <= 0 )
   {
     return (TEncTop *)getLayerEnc( 0 );
   }
 
-  return (TEncTop *)getLayerEnc( m_cVPS.getRefLayerId( m_layerId, refLayerIdx ) );
+  return (TEncTop *)getLayerEnc( m_cVPS.getLayerIdxInVps(m_cVPS.getRefLayerId( m_layerId, refLayerIdx )) );
 }
 #endif
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 1056)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 1057)
@@ -117,5 +117,5 @@
   static Int              m_iPPSIdCnt;                    ///< next Id number for PPS    
   TEncTop**               m_ppcTEncTop;
-  TEncTop*                getLayerEnc(UInt layerId)       { return m_ppcTEncTop[layerId]; }
+  TEncTop*                getLayerEnc(UInt layerIdx)       { return m_ppcTEncTop[layerIdx]; }
   TComPic*                m_cIlpPic[MAX_NUM_REF];                    ///<  Inter layer Prediction picture =  upsampled picture 
 #if REF_IDX_MFM
@@ -235,6 +235,6 @@
   Void      setNumRefLayerOffsets(Int x) { m_numRefLayerOffsets = x; }
   UInt      getNumRefLayerOffsets() { return m_numRefLayerOffsets; }
-  Void      setRefLayerId(Int x, UInt id) { m_refLayerId[x] = id;   }
-  UInt      getRefLayerId(Int x)          { return m_refLayerId[x]; }
+  Void      setRefLayerId(Int layerIdx, UInt layerId)     { m_refLayerId[layerIdx] = layerId;  }
+  UInt      getRefLayerId(Int layerIdx)                   { return m_refLayerId[layerIdx];     }
   Window&   getRefLayerWindowForLayer(Int layerId);
   Window&   getRefLayerWindow(Int x)            { return m_refLayerWindow[x]; }
