Index: /branches/SHM-dev/source/Lib/TLibCommon/TComLoopFilter.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 1247)
+++ /branches/SHM-dev/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 1248)
@@ -454,8 +454,4 @@
     else
     {
-      if (edgeDir == EDGE_HOR)
-      {
-        pcCUP = pcCUQ->getPUAbove(uiPartP, uiPartQ, !pCtu->getSlice()->getLFCrossSliceBoundaryFlag(), false, !m_bLFCrossTileBoundary);
-      }
       if (pcSlice->isInterB() || pcCUP->getSlice()->isInterB())
       {
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncCu.cpp	(revision 1247)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncCu.cpp	(revision 1248)
@@ -1380,5 +1380,4 @@
           }
 
-          rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth );
           Int orgQP = rpcTempCU->getQP( 0 );
           xCheckDQP( rpcTempCU );
@@ -1443,9 +1442,6 @@
   DEBUG_STRING_NEW(sTest)
 
+  // prior to this, rpcTempCU will have just been reset using rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
   UChar uhDepth = rpcTempCU->getDepth( 0 );
-
-  rpcTempCU->setDepthSubParts( uhDepth, 0 );
-
-  rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth );
 
   rpcTempCU->setPartSizeSubParts  ( ePartSize,  0, uhDepth );
Index: /branches/SHM-dev/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- /branches/SHM-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 1247)
+++ /branches/SHM-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 1248)
@@ -2275,5 +2275,5 @@
 #endif
 
-      for( Int i=0; i < numModesForFullRD; i++ ) 
+      for( Int i=0; i < numModesForFullRD; i++ )
       {
         CandCostList[ i ] = MAX_DOUBLE;
@@ -2334,5 +2334,5 @@
       pcCU->getIntraDirPredictor( uiPartOffset, uiPreds, COMPONENT_Y, &iMode );
 #endif
-      const Int numCand = ( iMode >= 0 ) ? iMode : Int(NUM_MOST_PROBABLE_MODES);      
+      const Int numCand = ( iMode >= 0 ) ? iMode : Int(NUM_MOST_PROBABLE_MODES);
 
       for( Int j=0; j < numCand; j++)
@@ -4515,4 +4515,7 @@
   UInt        uiHeight     = pcCU->getHeight( 0 );
 
+  // The pcCU is not marked as skip-mode at this point, and its coeffs and arlCoeffs will all be 0.
+  // due to prior calls to TComDataCU::initEstData(  );
+
   //  No residual coding : SKIP mode
   if ( bSkipRes )
@@ -4582,4 +4585,6 @@
   }
 
+  // TODO: there should be a check on the CU depth (but see to-do below regarding this feature) eg:
+  // bHighPass = (bHighPass && pcCU->getDepth(0) <= pcCU->getSlice()->getPPS()->getMaxCuDQPDepth());
 #if SVC_EXTENSION
   qpMin =  bHighPass ? Clip3( -pcCU->getSlice()->getQpBDOffsetY(), MAX_QP, pcCU->getQP(0) - m_iMaxDeltaQP ) : pcCU->getQP( 0 );
@@ -4594,9 +4599,16 @@
   TComTURecurse tuLevel0(pcCU, 0);
 
-  for ( qp = qpMin; qp <= qpMax; qp++ )
+  for ( qp = qpMin; qp <= qpMax; qp++ ) // TODO: see the to-do below about this loop.
   {
     dCost = 0.;
     uiBits = 0;
     uiDistortion = 0;
+
+    // TODO: see the to-do below. eg:
+    //if (qpMin != qpMax)
+    //{
+    //  pcCU->setQPSubParts(qp, 0, pcCU->getDepth(0));
+    //  pcCU->setSkipFlagSubParts(false, 0, pcCU->getDepth(0));
+    //}
 
     m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_CURR_BEST ] );
@@ -4621,5 +4633,6 @@
     }
 
-    if ( dZeroCost < dCost )
+    const Bool bRootCbf=pcCU->getQtRootCbf(0)!=0;
+    if ( dZeroCost < dCost || !bRootCbf )
     {
       if ( dZeroCost < dCost )
@@ -4634,7 +4647,13 @@
       {
         const ComponentID component = ComponentID(ch);
-        const UInt componentShift   = pcCU->getPic()->getComponentScaleX(component) + pcCU->getPic()->getComponentScaleY(component);
         ::memset( pcCU->getCbf( component ) , 0, uiQPartNum * sizeof(UChar) );
-        ::memset( pcCU->getCoeff(component), 0, (uiWidth*uiHeight*sizeof(TCoeff))>>componentShift );
+        if (qpMin != qpMax) // If there is only one iteration, then these will already be 0.
+        {
+          const UInt componentShift   = pcCU->getPic()->getComponentScaleX(component) + pcCU->getPic()->getComponentScaleY(component);
+          ::memset( pcCU->getCoeff(component), 0, (uiWidth*uiHeight*sizeof(TCoeff))>>componentShift );
+#if ADAPTIVE_QP_SELECTION
+          ::memset( pcCU->getArlCoeff(component), 0, (uiWidth*uiHeight*sizeof(TCoeff))>>componentShift );
+#endif
+        }
         ::memset( pcCU->getCrossComponentPredictionAlpha(component), 0, ( uiQPartNum * sizeof(Char) ) );
       }
@@ -4706,4 +4725,6 @@
   if( qpMin != qpMax && qpBest != qpMax )
   {
+    // TODO: this code has never been used, the qp doesn't change the QP coded, and the following assert prevented this code running.
+    //        also, skip flag got stuck-on, as nothing cleared it. Recommend removing this.
     assert( 0 ); // check
     m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_TEMP_BEST ] );
@@ -4724,4 +4745,6 @@
       ::memcpy( pcCU->getCrossComponentPredictionAlpha(compID),  m_phQTTempCrossComponentPredictionAlpha[compID], uiQPartNum * sizeof( Char ) );
     }
+    // TODO: see to-do above. eg:
+    // pcCU->setSkipFlagSubParts(  (pcCU->getMergeFlag( 0 ) && pcCU->getPartitionSize( 0 ) == SIZE_2Nx2N && !pcCU->getQtRootCbf( 0 )), 0, pcCU->getDepth(0) );
   }
   pcYuvRec->addClip ( pcYuvPred, pcYuvResiBest, 0, uiWidth );
@@ -4741,11 +4764,8 @@
   pcCU->getTotalCost()       = dCostBest;
 
-  if ( pcCU->isSkipped(0) )
-  {
-    static const UInt cbfZero[MAX_NUM_COMPONENT]={0,0,0};
-    pcCU->setCbfSubParts( cbfZero, 0, pcCU->getDepth( 0 ) );
-  }
-
-  pcCU->setQPSubParts( qpBest, 0, pcCU->getDepth(0) );
+  if( qpMin != qpMax) // TODO: see to-do above
+  {
+    pcCU->setQPSubParts( qpBest, 0, pcCU->getDepth(0) );
+  }
 }
 
@@ -5475,5 +5495,5 @@
 
 
-Void TEncSearch::xSetResidualQTData( TComYuv* pcResi, Bool bSpatial, TComTU &rTu )
+Void TEncSearch::xSetResidualQTData( TComYuv* pcResi, Bool bSpatial, TComTU &rTu ) // TODO: turn this into two functions for bSpatial=true and false.
 {
   TComDataCU* pcCU=rTu.getCU();
