Index: /branches/HTM-DEV-0.3-dev0/source/App/TAppDecoder/TAppDecTop.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev0/source/App/TAppDecoder/TAppDecTop.cpp	(revision 496)
+++ /branches/HTM-DEV-0.3-dev0/source/App/TAppDecoder/TAppDecTop.cpp	(revision 497)
@@ -152,6 +152,5 @@
   Int  pocCurrPic        = -MAX_INT;     
   Int  pocLastPic        = -MAX_INT;   
-  
-  Int  layerIdLastPic    = 0; 
+
   Int  layerIdCurrPic    = 0; 
 
@@ -230,5 +229,4 @@
         if ( bNewPicture || !bitstreamFile )
         { 
-          layerIdLastPic    = layerIdCurrPic;  
           layerIdCurrPic    = nalu.m_layerId; 
           
Index: /branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComSlice.cpp	(revision 496)
+++ /branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComSlice.cpp	(revision 497)
@@ -517,7 +517,6 @@
   TComPic*  rpsCurrList1[MAX_NUM_REF+1];
 
-#if H_MV
-  
-  Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + getNumActiveRefLayerPics( );
+#if H_MV  
+  Int numPocTotalCurr = ( getInterRefEnabledInRPLFlag() ? ( NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr ) : 0 ) + getNumActiveRefLayerPics( );
   assert( numPocTotalCurr == getNumRpsCurrTempList() );
 #else
@@ -613,4 +612,28 @@
   ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm));
 
+#if H_MV
+  Int numPocSt = getInterRefEnabledInRPLFlag( ) ?  (NumPocStCurr0 + NumPocStCurr1) : 0; 
+
+  for (Int li = 0; li < 2; li++)
+  {
+    if ( m_eSliceType == P_SLICE && li == 1 )
+    {
+      m_aiNumRefIdx[1] = 0;
+      ::memset( m_apcRefPicList[1], 0, sizeof(m_apcRefPicList[1]));
+    } 
+    else
+    {
+      for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[ li ] - 1 ); rIdx ++)
+      { 
+        Bool listModified             =                m_RefPicListModification.getRefPicListModificationFlagL( li ); 
+        Int orgIdx                    = listModified ? m_RefPicListModification.getRefPicSetIdxL(li, rIdx) : (rIdx % numPocTotalCurr); 
+
+        m_apcRefPicList    [li][rIdx] = ( li == 0 )  ? rpsCurrList0[ orgIdx  ] : rpsCurrList1[ orgIdx  ];
+        m_bIsUsedAsLongTerm[li][rIdx] = ( orgIdx >= numPocSt ) ; 
+      }
+    }
+  }
+#else
+
   for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[0]-1); rIdx ++)
   {
@@ -633,4 +656,5 @@
     }
   }
+#endif
 }
 
@@ -669,5 +693,5 @@
   }
 #if H_MV
-  numRpsCurrTempList = numRpsCurrTempList + getNumActiveRefLayerPics();
+  numRpsCurrTempList = ( getInterRefEnabledInRPLFlag() ? numRpsCurrTempList : 0 ) + getNumActiveRefLayerPics();
 #endif
   return numRpsCurrTempList;
Index: /branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- /branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComSlice.h	(revision 496)
+++ /branches/HTM-DEV-0.3-dev0/source/Lib/TLibCommon/TComSlice.h	(revision 497)
@@ -1266,6 +1266,8 @@
 #if H_MV
   // Why not an listIdx for all members, would avoid code duplication?? 
-  Void       setRefPicSetIdxL(UInt li, UInt idx, UInt refPicSetIdx) {( li==0 ? m_RefPicSetIdxL0[idx] : m_RefPicSetIdxL1[idx] ) = refPicSetIdx; };
-  Void       setRefPicListModificationFlagL(UInt li, Bool flag) { ( li==0  ? m_bRefPicListModificationFlagL0 : m_bRefPicListModificationFlagL1 ) = flag;  };  
+  Void       setRefPicSetIdxL(UInt li, UInt idx, UInt refPicSetIdx) {( li==0 ? m_RefPicSetIdxL0[idx] : m_RefPicSetIdxL1[idx] ) = refPicSetIdx; }
+  UInt       getRefPicSetIdxL(UInt li, UInt idx ) { return ( li == 0 ) ? m_RefPicSetIdxL0[idx] : m_RefPicSetIdxL1[idx] ; }
+  Void       setRefPicListModificationFlagL(UInt li, Bool flag) { ( li==0  ? m_bRefPicListModificationFlagL0 : m_bRefPicListModificationFlagL1 ) = flag;  }
+  Bool       getRefPicListModificationFlagL(UInt li ) { return ( li== 0) ? m_bRefPicListModificationFlagL0 : m_bRefPicListModificationFlagL1; }
 #endif
 };
Index: /branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- /branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 496)
+++ /branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 497)
@@ -691,5 +691,6 @@
     pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(gopEntry.m_numRefPicsActive,( pcSlice->getRPS()->getNumberOfPictures() + (Int) m_refPicSetInterLayer.size() ) ) );
     pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(gopEntry.m_numRefPicsActive,( pcSlice->getRPS()->getNumberOfPictures() + (Int) m_refPicSetInterLayer.size() ) ) );
-    xSetRefPicListModificationsMvc( pcSlice, iGOPid );    
+
+    xSetRefPicListModificationsMv( pcSlice, iGOPid );    
 
     pcSlice->setActiveMotionPredRefLayers( );
@@ -2948,10 +2949,9 @@
 #endif
 #if H_MV
-Void TEncGOP::xSetRefPicListModificationsMvc( TComSlice* pcSlice, UInt iGOPid )
-{ 
-  TComVPS* vps = pcSlice->getVPS(); 
+Void TEncGOP::xSetRefPicListModificationsMv( TComSlice* pcSlice, UInt iGOPid )
+{   
   Int layer    = pcSlice->getLayerIdInVps( ); 
   
-  if( pcSlice->getSliceType() == I_SLICE || !(pcSlice->getPPS()->getListsModificationPresentFlag()) || vps->getNumDirectRefLayers( layer ) == 0 )
+  if( pcSlice->getSliceType() == I_SLICE || !(pcSlice->getPPS()->getListsModificationPresentFlag()) || pcSlice->getNumActiveRefLayerPics() == 0 )
   {
     return;
@@ -2960,65 +2960,53 @@
   // analyze inter-view modifications
   GOPEntry ge = m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && ( layer > 0) ) ? MAX_GOP : iGOPid );
-
-  TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
-  
+  assert( ge.m_numActiveRefLayerPics == pcSlice->getNumActiveRefLayerPics() ); 
+
   Int maxRefListSize  = pcSlice->getNumRpsCurrTempList();
-  Int numTemporalRefs = maxRefListSize - vps->getNumDirectRefLayers( layer );
-
-
+  Int numTemporalRefs = maxRefListSize - pcSlice->getNumActiveRefLayerPics();
+  
   for (Int li = 0; li < 2; li ++) // Loop over lists L0 and L1
   {
-    Int numModifications = 0;
-    
-    for( Int k = 0; k < ge.m_numActiveRefLayerPics; k++ ) 
-    {
-      numModifications +=  ( ge.m_interViewRefPosL[li][k] >= 0 ) ? 1 : 0; 
-    }
-
-    // set inter-view modifications
+    // set inter-view modifications    
+    Int tempList[16];
+    for( Int k = 0; k < 16; k++ )
+    { 
+      tempList[ k ] = -1;
+    }
+
     Bool isModified = false;
-      Int tempList[16];
-      for( Int k = 0; k < 16; k++ ) { tempList[k] = -1; }
-
-    if( (maxRefListSize > 1) && (numModifications > 0) )
-    {
-      for( Int k = 0; k < ge.m_numActiveRefLayerPics; k++ )
-      {
-        if( ge.m_interViewRefPosL[li][k] >= 0 )
-        {
-          Int orgIdx    = numTemporalRefs;
-          Int targetIdx = ge.m_interViewRefPosL[ li ][ k ];
-          for( Int idx = 0; idx < vps->getNumDirectRefLayers( layer ); idx++ )
-          {            
-            Int refLayer  = vps->getLayerIdInVps( vps->getRefLayerId( layer, idx ) );          
-            if( ( layer + ge.m_interLayerPredLayerIdc[ k ]) == refLayer )
-            {
-              tempList[ targetIdx ] = orgIdx;              
-              isModified = ( targetIdx != orgIdx  );
-            }
-            orgIdx++;
-          }
-        }
-      }
-    }
-
+    if ( maxRefListSize > 1 )
+    {      
+      for( Int k = 0, orgIdx = numTemporalRefs; k < ge.m_numActiveRefLayerPics; k++, orgIdx++ )
+      {
+        Int targetIdx = ge.m_interViewRefPosL[ li ][ k ];
+
+        isModified = ( targetIdx != orgIdx ) && ( targetIdx >= 0  );
+        if ( isModified )
+        {
+          assert( tempList[ targetIdx ] == -1 ); // Assert when two inter layer reference pictures are sorted to the same position
+          tempList[ targetIdx ] = orgIdx;              
+        }
+      }      
+    }
+
+    TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
     refPicListModification->setRefPicListModificationFlagL( li, isModified );  
 
-      if( isModified )
-      {
-        Int temporalRefIdx = 0;
-        for( Int i = 0; i < pcSlice->getNumRefIdx( ( li == 0 ) ? REF_PIC_LIST_0 : REF_PIC_LIST_1 ); i++ )
-        {
-          if( tempList[i] >= 0 ) 
-          {
-            refPicListModification->setRefPicSetIdxL( li, i, tempList[i] );
-          }
-          else
-          {
-            refPicListModification->setRefPicSetIdxL( li, i, temporalRefIdx );
-            temporalRefIdx++;
-          }
-        }
-      }
+    if( isModified )
+    {
+      Int temporalRefIdx = 0;
+      for( Int i = 0; i < pcSlice->getNumRefIdx( ( li == 0 ) ? REF_PIC_LIST_0 : REF_PIC_LIST_1 ); i++ )
+      {
+        if( tempList[i] >= 0 ) 
+        {
+          refPicListModification->setRefPicSetIdxL( li, i, tempList[i] );
+        }
+        else
+        {
+          refPicListModification->setRefPicSetIdxL( li, i, temporalRefIdx );
+          temporalRefIdx++;
+        }
+      }
+    }
   }
 }
Index: /branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- /branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncGOP.h	(revision 496)
+++ /branches/HTM-DEV-0.3-dev0/source/Lib/TLibEncoder/TEncGOP.h	(revision 497)
@@ -221,5 +221,5 @@
 #endif
 #if H_MV
-   Void  xSetRefPicListModificationsMvc( TComSlice* pcSlice, UInt iGOPid );
+   Void  xSetRefPicListModificationsMv( TComSlice* pcSlice, UInt iGOPid );
 #endif
 #if L0386_DB_METRIC
