Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/SEIwrite.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 534)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/SEIwrite.cpp	(revision 537)
@@ -84,19 +84,13 @@
     fprintf( g_hTrace, "=========== Decoding Unit Information SEI message ===========\n");
     break;
-#if J0149_TONE_MAPPING_SEI
   case SEI::TONE_MAPPING_INFO:
     fprintf( g_hTrace, "=========== Tone Mapping Info SEI message ===========\n");
     break;
-#endif
-#if L0208_SOP_DESCRIPTION_SEI
   case SEI::SOP_DESCRIPTION:
     fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
     break;
-#endif
-#if K0180_SCALABLE_NESTING_SEI
   case SEI::SCALABLE_NESTING:
     fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
     break;
-#endif
   default:
     fprintf( g_hTrace, "=========== Unknown SEI message ===========\n");
@@ -106,9 +100,5 @@
 #endif
 
-#if K0180_SCALABLE_NESTING_SEI
 void SEIWriter::xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComSPS *sps)
-#else
-void SEIWriter::xWriteSEIpayloadData(const SEI& sei, TComSPS *sps)
-#endif
 {
   switch (sei.payloadType())
@@ -147,19 +137,13 @@
     xWriteSEIGradualDecodingRefreshInfo(*static_cast<const SEIGradualDecodingRefreshInfo*>(&sei));
     break;
-#if J0149_TONE_MAPPING_SEI
   case SEI::TONE_MAPPING_INFO:
     xWriteSEIToneMappingInfo(*static_cast<const SEIToneMappingInfo*>(&sei));
     break;
-#endif
-#if L0208_SOP_DESCRIPTION_SEI
   case SEI::SOP_DESCRIPTION:
     xWriteSEISOPDescription(*static_cast<const SEISOPDescription*>(&sei));
     break;
-#endif
-#if K0180_SCALABLE_NESTING_SEI
   case SEI::SCALABLE_NESTING:
     xWriteSEIScalableNesting(bs, *static_cast<const SEIScalableNesting*>(&sei), sps);
     break;
-#endif
   default:
     assert(!"Unhandled SEI message");
@@ -179,6 +163,4 @@
   setBitstream(&bs_count);
 
-
-#if K0180_SCALABLE_NESTING_SEI
 
 #if ENC_DEC_TRACE
@@ -191,16 +173,4 @@
 #endif
 
-#else
-
-#if ENC_DEC_TRACE
-  g_HLSTraceEnable = false;
-#endif
-  xWriteSEIpayloadData(sei, sps);
-#if ENC_DEC_TRACE
-  g_HLSTraceEnable = true;
-#endif
-
-#endif
-
   UInt payload_data_num_bits = bs_count.getNumberOfWrittenBits();
   assert(0 == payload_data_num_bits % 8);
@@ -209,7 +179,5 @@
 
 #if ENC_DEC_TRACE
-#if K0180_SCALABLE_NESTING_SEI
   if (g_HLSTraceEnable)
-#endif
   xTraceSEIHeader();
 #endif
@@ -231,15 +199,9 @@
   /* payloadData */
 #if ENC_DEC_TRACE
-#if K0180_SCALABLE_NESTING_SEI
   if (g_HLSTraceEnable)
-#endif
   xTraceSEIMessageType(sei.payloadType());
 #endif
 
-#if K0180_SCALABLE_NESTING_SEI
   xWriteSEIpayloadData(bs, sei, sps);
-#else
-  xWriteSEIpayloadData(sei, sps);
-#endif
 }
 
@@ -296,8 +258,6 @@
 {
   WRITE_CODE(sei.activeVPSId,     4, "active_vps_id");
-#if L0047_APS_FLAGS
   WRITE_FLAG(sei.m_fullRandomAccessFlag, "full_random_access_flag");
   WRITE_FLAG(sei.m_noParamSetUpdateFlag, "no_param_set_update_flag");
-#endif
   WRITE_UVLC(sei.numSpsIdsMinus1,    "num_sps_ids_minus1");
 
@@ -330,5 +290,4 @@
     WRITE_CODE( sei.m_duSptCpbRemovalDelay, (vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1), "du_spt_cpb_removal_delay");
   }
-#if L0044_DU_DPB_OUTPUT_DELAY_HRD
   WRITE_FLAG( sei.m_dpbOutputDuDelayPresentFlag, "dpb_output_du_delay_present_flag");
   if(sei.m_dpbOutputDuDelayPresentFlag)
@@ -336,5 +295,4 @@
     WRITE_CODE(sei.m_picSptDpbOutputDuDelay, vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, "pic_spt_dpb_output_du_delay");
   }
-#endif
   xWriteByteAlign();
 }
@@ -351,9 +309,6 @@
     WRITE_FLAG( sei.m_rapCpbParamsPresentFlag, "rap_cpb_params_present_flag" );
   }
-#if L0328_SPLICING
   WRITE_FLAG( sei.m_concatenationFlag, "concatenation_flag");
   WRITE_CODE( sei.m_auCpbRemovalDelayDelta - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), "au_cpb_removal_delay_delta_minus1" );
-#endif
-#if L0044_CPB_DPB_DELAY_OFFSET
   if( sei.m_rapCpbParamsPresentFlag )
   {
@@ -361,5 +316,4 @@
     WRITE_CODE( sei.m_dpbDelayOffset, hrd->getDpbOutputDelayLengthMinus1()  + 1, "dpb_delay_offset" );
   }
-#endif
   for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
   {
@@ -387,32 +341,19 @@
   TComHRD *hrd = vui->getHrdParameters();
 
-#if !L0045_CONDITION_SIGNALLING
-  // This condition was probably OK before the pic_struct, progressive_source_idc, duplicate_flag were added
-  if( !hrd->getNalHrdParametersPresentFlag() && !hrd->getVclHrdParametersPresentFlag() )
-    return;
-#endif
   if( vui->getFrameFieldInfoPresentFlag() )
   {
     WRITE_CODE( sei.m_picStruct, 4,              "pic_struct" );
-#if L0046_RENAME_PROG_SRC_IDC
     WRITE_CODE( sei.m_sourceScanType, 2,         "source_scan_type" );
-#else
-    WRITE_CODE( sei.m_progressiveSourceIdc, 2,   "progressive_source_idc" );
-#endif
     WRITE_FLAG( sei.m_duplicateFlag ? 1 : 0,     "duplicate_flag" );
   }
 
-#if L0045_CONDITION_SIGNALLING
   if( hrd->getCpbDpbDelaysPresentFlag() )
   {
-#endif
     WRITE_CODE( sei.m_auCpbRemovalDelay - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ),                                         "au_cpb_removal_delay_minus1" );
     WRITE_CODE( sei.m_picDpbOutputDelay, ( hrd->getDpbOutputDelayLengthMinus1() + 1 ),                                          "pic_dpb_output_delay" );
-#if L0044_DU_DPB_OUTPUT_DELAY_HRD
     if(hrd->getSubPicCpbParamsPresentFlag())
     {
       WRITE_CODE(sei.m_picDpbOutputDuDelay, hrd->getDpbOutputDelayDuLengthMinus1()+1, "pic_dpb_output_du_delay" );
     }
-#endif
     if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
     {
@@ -432,7 +373,5 @@
       }
     }
-#if L0045_CONDITION_SIGNALLING
-  }
-#endif
+  }
   xWriteByteAlign();
 }
@@ -471,9 +410,5 @@
 
     WRITE_CODE( sei.m_arrangementReservedByte, 8,   "frame_packing_arrangement_reserved_byte" );
-#if L0045_PERSISTENCE_FLAGS
     WRITE_FLAG( sei.m_arrangementPersistenceFlag,   "frame_packing_arrangement_persistence_flag" );
-#else
-    WRITE_UVLC( sei.m_arrangementRepetetionPeriod,  "frame_packing_arrangement_repetition_period" );
-#endif
   }
 
@@ -483,5 +418,4 @@
 }
 
-#if J0149_TONE_MAPPING_SEI
 Void SEIWriter::xWriteSEIToneMappingInfo(const SEIToneMappingInfo& sei)
 {
@@ -555,5 +489,4 @@
   xWriteByteAlign();
 }
-#endif
 
 Void SEIWriter::xWriteSEIDisplayOrientation(const SEIDisplayOrientation &sei)
@@ -565,13 +498,5 @@
     WRITE_FLAG( sei.verFlip,                   "ver_flip" );
     WRITE_CODE( sei.anticlockwiseRotation, 16, "anticlockwise_rotation" );
-#if L0045_PERSISTENCE_FLAGS
     WRITE_FLAG( sei.persistenceFlag,          "display_orientation_persistence_flag" );
-#else
-    WRITE_UVLC( sei.repetitionPeriod,          "display_orientation_repetition_period" );
-#endif
-#if !REMOVE_SINGLE_SEI_EXTENSION_FLAGS
-    WRITE_FLAG( sei.extensionFlag,             "display_orientation_extension_flag" );
-    assert( !sei.extensionFlag );
-#endif
   }
   xWriteByteAlign();
@@ -591,5 +516,4 @@
 }
 
-#if L0208_SOP_DESCRIPTION_SEI
 Void SEIWriter::xWriteSEISOPDescription(const SEISOPDescription& sei)
 {
@@ -612,7 +536,5 @@
   xWriteByteAlign();
 }
-#endif
-
-#if K0180_SCALABLE_NESTING_SEI
+
 Void SEIWriter::xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps)
 {
@@ -656,5 +578,4 @@
   }
 }
-#endif
 
 Void SEIWriter::xWriteByteAlign()
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/SEIwrite.h
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/SEIwrite.h	(revision 534)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/SEIwrite.h	(revision 537)
@@ -50,9 +50,5 @@
 
 protected:
-#if K0180_SCALABLE_NESTING_SEI
   Void xWriteSEIpayloadData(TComBitIf& bs, const SEI& sei, TComSPS *sps);
-#else
-  Void xWriteSEIpayloadData(const SEI& sei, TComSPS *sps);
-#endif
   Void xWriteSEIuserDataUnregistered(const SEIuserDataUnregistered &sei);
   Void xWriteSEIActiveParameterSets(const SEIActiveParameterSets& sei);
@@ -67,13 +63,7 @@
   Void xWriteSEITemporalLevel0Index(const SEITemporalLevel0Index &sei);
   Void xWriteSEIGradualDecodingRefreshInfo(const SEIGradualDecodingRefreshInfo &sei);
-#if J0149_TONE_MAPPING_SEI
   Void xWriteSEIToneMappingInfo(const SEIToneMappingInfo& sei);
-#endif
-#if L0208_SOP_DESCRIPTION_SEI
   Void xWriteSEISOPDescription(const SEISOPDescription& sei);
-#endif
-#if K0180_SCALABLE_NESTING_SEI
   Void xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps);
-#endif
   Void xWriteByteAlign();
 };
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 534)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 537)
@@ -172,8 +172,6 @@
   WRITE_UVLC( pcPPS->getSPSId(),                             "pps_seq_parameter_set_id" );
   WRITE_FLAG( pcPPS->getDependentSliceSegmentsEnabledFlag()    ? 1 : 0, "dependent_slice_segments_enabled_flag" );
-#if L0255_MOVE_PPS_FLAGS
   WRITE_FLAG( pcPPS->getOutputFlagPresentFlag() ? 1 : 0,     "output_flag_present_flag" );
   WRITE_CODE( pcPPS->getNumExtraSliceHeaderBits(), 3,        "num_extra_slice_header_bits");
-#endif
   WRITE_FLAG( pcPPS->getSignHideFlag(), "sign_data_hiding_flag" );
   WRITE_FLAG( pcPPS->getCabacInitPresentFlag() ? 1 : 0,   "cabac_init_present_flag" );
@@ -195,7 +193,4 @@
   WRITE_FLAG( pcPPS->getUseWP() ? 1 : 0,  "weighted_pred_flag" );   // Use of Weighting Prediction (P_SLICE)
   WRITE_FLAG( pcPPS->getWPBiPred() ? 1 : 0, "weighted_bipred_flag" );  // Use of Weighting Bi-Prediction (B_SLICE)
-#if !L0255_MOVE_PPS_FLAGS
-  WRITE_FLAG( pcPPS->getOutputFlagPresentFlag() ? 1 : 0,  "output_flag_present_flag" );
-#endif
   WRITE_FLAG( pcPPS->getTransquantBypassEnableFlag() ? 1 : 0, "transquant_bypass_enable_flag" );
   WRITE_FLAG( pcPPS->getTilesEnabledFlag()             ? 1 : 0, "tiles_enabled_flag" );
@@ -244,7 +239,4 @@
   WRITE_FLAG( pcPPS->getListsModificationPresentFlag(), "lists_modification_present_flag");
   WRITE_UVLC( pcPPS->getLog2ParallelMergeLevelMinus2(), "log2_parallel_merge_level_minus2");
-#if !L0255_MOVE_PPS_FLAGS
-  WRITE_CODE( pcPPS->getNumExtraSliceHeaderBits(), 3, "num_extra_slice_header_bits");
-#endif
   WRITE_FLAG( pcPPS->getSliceHeaderExtensionPresentFlag() ? 1 : 0, "slice_segment_header_extension_present_flag");
   WRITE_FLAG( 0, "pps_extension_flag" );
@@ -305,5 +297,4 @@
     WRITE_UVLC(defaultDisplayWindow.getWindowBottomOffset(),    "def_disp_win_bottom_offset");
   }
-#if L0043_TIMING_INFO
   TimingInfo *timingInfo = pcVUI->getTimingInfo();
   WRITE_FLAG(timingInfo->getTimingInfoPresentFlag(),          "vui_timing_info_present_flag");
@@ -317,5 +308,4 @@
       WRITE_UVLC(timingInfo->getNumTicksPocDiffOneMinus1(),   "vui_num_ticks_poc_diff_one_minus1");
     }
-#endif
   WRITE_FLAG(pcVUI->getHrdParametersPresentFlag(),              "hrd_parameters_present_flag");
   if( pcVUI->getHrdParametersPresentFlag() )
@@ -323,14 +313,5 @@
     codeHrdParameters(pcVUI->getHrdParameters(), 1, pcSPS->getMaxTLayers() - 1 );
   }
-#if L0043_TIMING_INFO
-  }
-#endif
-#if !L0043_TIMING_INFO
-  WRITE_FLAG( pcVUI->getPocProportionalToTimingFlag(), "poc_proportional_to_timing_flag" );
-  if( pcVUI->getPocProportionalToTimingFlag() && pcVUI->getHrdParameters()->getTimingInfoPresentFlag() )
-  {
-    WRITE_UVLC( pcVUI->getNumTicksPocDiffOneMinus1(), "num_ticks_poc_diff_one_minus1" );
-  }
-#endif
+  }
 
   WRITE_FLAG(pcVUI->getBitstreamRestrictionFlag(),              "bitstream_restriction_flag");
@@ -346,9 +327,5 @@
     WRITE_FLAG(pcVUI->getMotionVectorsOverPicBoundariesFlag(),  "motion_vectors_over_pic_boundaries_flag");
     WRITE_FLAG(pcVUI->getRestrictedRefPicListsFlag(),           "restricted_ref_pic_lists_flag");
-#if L0043_MSS_IDC
     WRITE_UVLC(pcVUI->getMinSpatialSegmentationIdc(),           "min_spatial_segmentation_idc");
-#else
-    WRITE_CODE(pcVUI->getMinSpatialSegmentationIdc(),        8, "min_spatial_segmentation_idc");
-#endif
     WRITE_UVLC(pcVUI->getMaxBytesPerPicDenom(),                 "max_bytes_per_pic_denom");
     WRITE_UVLC(pcVUI->getMaxBitsPerMinCuDenom(),                "max_bits_per_mincu_denom");
@@ -362,12 +339,4 @@
   if( commonInfPresentFlag )
   {
-#if !L0043_TIMING_INFO
-    WRITE_FLAG( hrd->getTimingInfoPresentFlag() ? 1 : 0,        "timing_info_present_flag" );
-    if( hrd->getTimingInfoPresentFlag() )
-    {
-      WRITE_CODE( hrd->getNumUnitsInTick(), 32,                  "num_units_in_tick" );
-      WRITE_CODE( hrd->getTimeScale(),      32,                  "time_scale" );
-    }
-#endif
     WRITE_FLAG( hrd->getNalHrdParametersPresentFlag() ? 1 : 0 ,  "nal_hrd_parameters_present_flag" );
     WRITE_FLAG( hrd->getVclHrdParametersPresentFlag() ? 1 : 0 ,  "vcl_hrd_parameters_present_flag" );
@@ -380,7 +349,5 @@
         WRITE_CODE( hrd->getDuCpbRemovalDelayLengthMinus1(), 5,  "du_cpb_removal_delay_length_minus1" );
         WRITE_FLAG( hrd->getSubPicCpbParamsInPicTimingSEIFlag() ? 1 : 0, "sub_pic_cpb_params_in_pic_timing_sei_flag" );
-#if L0044_DU_DPB_OUTPUT_DELAY_HRD
         WRITE_CODE( hrd->getDpbOutputDelayDuLengthMinus1(), 5,   "dpb_output_delay_du_length_minus1"  );
-#endif
       }
       WRITE_CODE( hrd->getBitRateScale(), 4,                     "bit_rate_scale" );
@@ -411,5 +378,4 @@
       WRITE_UVLC( hrd->getPicDurationInTcMinus1( i ),           "elemental_duration_in_tc_minus1");
     }
-#if L0372
     else
     {
@@ -420,8 +386,4 @@
       WRITE_UVLC( hrd->getCpbCntMinus1( i ),                      "cpb_cnt_minus1");
     }
-#else
-    WRITE_FLAG( hrd->getLowDelayHrdFlag( i ) ? 1 : 0,           "low_delay_hrd_flag");
-    WRITE_UVLC( hrd->getCpbCntMinus1( i ),                      "cpb_cnt_minus1");
-#endif
     
     for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
@@ -436,8 +398,6 @@
           if( hrd->getSubPicCpbParamsPresentFlag() )
           {
-#if L0363_DU_BIT_RATE
+            WRITE_UVLC( hrd->getDuCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_du_value_minus1");  
             WRITE_UVLC( hrd->getDuBitRateValueMinus1( i, j, nalOrVcl ), "bit_rate_du_value_minus1");
-#endif
-            WRITE_UVLC( hrd->getDuCpbSizeValueMinus1( i, j, nalOrVcl ), "cpb_size_du_value_minus1");  
           }
           WRITE_FLAG( hrd->getCbrFlag( i, j, nalOrVcl ) ? 1 : 0, "cbr_flag");
@@ -499,11 +459,7 @@
   for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
   {
-#if L0323_DPB
     WRITE_UVLC( pcSPS->getMaxDecPicBuffering(i) - 1,       "sps_max_dec_pic_buffering_minus1[i]" );
-#else
-    WRITE_UVLC( pcSPS->getMaxDecPicBuffering(i),           "sps_max_dec_pic_buffering[i]" );
-#endif
     WRITE_UVLC( pcSPS->getNumReorderPics(i),               "sps_num_reorder_pics[i]" );
-    WRITE_UVLC( pcSPS->getMaxLatencyIncrease(i),           "sps_max_latency_increase[i]" );
+    WRITE_UVLC( pcSPS->getMaxLatencyIncrease(i),           "sps_max_latency_increase_plus1[i]" );
     if (!subLayerOrderingInfoPresentFlag)
     {
@@ -642,18 +598,11 @@
 #endif
   codePTL( pcVPS->getPTL(), true, pcVPS->getMaxTLayers() - 1 );
-#if SIGNAL_BITRATE_PICRATE_IN_VPS
-  codeBitratePicRateInfo(pcVPS->getBitratePicrateInfo(), 0, pcVPS->getMaxTLayers() - 1);
-#endif  
   const Bool subLayerOrderingInfoPresentFlag = 1;
   WRITE_FLAG(subLayerOrderingInfoPresentFlag,              "vps_sub_layer_ordering_info_present_flag");
   for(UInt i=0; i <= pcVPS->getMaxTLayers()-1; i++)
   {
-#if L0323_DPB
     WRITE_UVLC( pcVPS->getMaxDecPicBuffering(i) - 1,       "vps_max_dec_pic_buffering_minus1[i]" );
-#else
-    WRITE_UVLC( pcVPS->getMaxDecPicBuffering(i),           "vps_max_dec_pic_buffering[i]" );
-#endif
     WRITE_UVLC( pcVPS->getNumReorderPics(i),               "vps_num_reorder_pics[i]" );
-    WRITE_UVLC( pcVPS->getMaxLatencyIncrease(i),           "vps_max_latency_increase[i]" );
+    WRITE_UVLC( pcVPS->getMaxLatencyIncrease(i),           "vps_max_latency_increase_plus1[i]" );
     if (!subLayerOrderingInfoPresentFlag)
     {
@@ -676,5 +625,4 @@
   assert( pcVPS->getMaxNuhReservedZeroLayerId() < MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 );
   WRITE_CODE( pcVPS->getMaxNuhReservedZeroLayerId(), 6,     "vps_max_nuh_reserved_zero_layer_id" );
-
   pcVPS->setMaxOpSets(1);
   WRITE_UVLC( pcVPS->getMaxOpSets() - 1,                    "vps_max_op_sets_minus1" );
@@ -690,5 +638,4 @@
     }
   }
-#if L0043_TIMING_INFO
   TimingInfo *timingInfo = pcVPS->getTimingInfo();
   WRITE_FLAG(timingInfo->getTimingInfoPresentFlag(),          "vps_timing_info_present_flag");
@@ -702,5 +649,4 @@
       WRITE_UVLC(timingInfo->getNumTicksPocDiffOneMinus1(),   "vps_num_ticks_poc_diff_one_minus1");
     }
-#endif
     pcVPS->setNumHrdParameters( 0 );
     WRITE_UVLC( pcVPS->getNumHrdParameters(),                 "vps_num_hrd_parameters" );
@@ -721,7 +667,5 @@
       codeHrdParameters(pcVPS->getHrdParameters(i), pcVPS->getCprmsPresentFlag( i ), pcVPS->getMaxTLayers() - 1);
     }
-#if L0043_TIMING_INFO
-  }
-#endif
+  }
 #if H_MV
   WRITE_FLAG( 1,                                             "vps_extension_flag" );
@@ -983,16 +927,11 @@
     //   colour_plane_id                                      u(2)
 
-#if H_MV && !H_MV_FIX1071
-    // Temporary fix for FIX1071 should be removed later
-    TComReferencePictureSet* rps = pcSlice->getRPS();
-#endif      
     if( !pcSlice->getIdrPicFlag() )
     {
       Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC());
       WRITE_CODE( picOrderCntLSB, pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb");
-#if !H_MV || H_MV_FIX1071
       TComReferencePictureSet* rps = pcSlice->getRPS();
-#endif      
-#if FIX1071 && H_MV_FIX1071
+      
+#if FIX1071
       // check for bitstream restriction stating that:
       // If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
@@ -1006,30 +945,6 @@
         }
 #endif
-#if FIX1071 && !H_MV_FIX1071
-      // Deal with bitstream restriction stating that:
-      // – If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
-      // Ideally this process should not be repeated for each slice in a picture
-      TComReferencePictureSet altRps;
-      Bool useAltRps = false;
-      if (pcSlice->getRapPicFlag())
-      {
-        for (Int picIdx = 0; !useAltRps && picIdx < rps->getNumberOfPictures(); picIdx++)
-        {
-          useAltRps = rps->getUsed(picIdx);
-        }
-        if (useAltRps)
-        {
-          memcpy(&altRps, rps, sizeof(TComReferencePictureSet));
-          rps = &altRps;
-          for (Int picIdx = 0; picIdx < rps->getNumberOfPictures(); picIdx++)
-          {
-            rps->setUsed(picIdx, false);
-          }
-        }
-      }
-      if(pcSlice->getRPSidx() < 0 || useAltRps)
-#else
+
       if(pcSlice->getRPSidx() < 0)
-#endif
       {
         WRITE_FLAG( 0, "short_term_ref_pic_set_sps_flag");
@@ -1188,10 +1103,6 @@
       pcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
     }
-#if H_MV && !H_MV_FIX1071
-    // Temporary fix for FIX1071 should be removed later
-    if( pcSlice->getPPS()->getListsModificationPresentFlag() && pcSlice->getNumRpsCurrTempList( rps ) > 1)
-#else
+
     if( pcSlice->getPPS()->getListsModificationPresentFlag() && pcSlice->getNumRpsCurrTempList() > 1)
-#endif
     {
       TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
@@ -1385,5 +1296,4 @@
   WRITE_CODE( pcPTL->getGeneralPTL()->getLevelIdc(), 8, "general_level_idc" );
 
-#if L0363_BYTE_ALIGN
   for (Int i = 0; i < maxNumSubLayersMinus1; i++)
   {
@@ -1407,16 +1317,7 @@
     }
   }
-#endif
   
   for(Int i = 0; i < maxNumSubLayersMinus1; i++)
   {
-#if !L0363_BYTE_ALIGN
-    if(profilePresentFlag)
-    {
-      WRITE_FLAG( pcPTL->getSubLayerProfilePresentFlag(i), "sub_layer_profile_present_flag[i]" );
-    }
-
-    WRITE_FLAG( pcPTL->getSubLayerLevelPresentFlag(i),   "sub_layer_level_present_flag[i]" );
-#endif
     if( profilePresentFlag && pcPTL->getSubLayerProfilePresentFlag(i) )
     {
@@ -1439,5 +1340,4 @@
   }
 
-#if L0046_CONSTRAINT_FLAGS
   WRITE_FLAG(ptl->getProgressiveSourceFlag(),   "general_progressive_source_flag");
   WRITE_FLAG(ptl->getInterlacedSourceFlag(),    "general_interlaced_source_flag");
@@ -1448,32 +1348,6 @@
   WRITE_CODE(0 , 16, "XXX_reserved_zero_44bits[16..31]");
   WRITE_CODE(0 , 12, "XXX_reserved_zero_44bits[32..43]");
-#elif L0363_MORE_BITS
-  WRITE_CODE(0 , 16, "XXX_reserved_zero_48bits[0..15]");
-  WRITE_CODE(0 , 16, "XXX_reserved_zero_48bits[16..31]");
-  WRITE_CODE(0 , 16, "XXX_reserved_zero_48bits[32..47]");
-#else
-  WRITE_CODE(0 , 16, "XXX_reserved_zero_16bits[]");
-#endif
-}
-#if SIGNAL_BITRATE_PICRATE_IN_VPS
-Void TEncCavlc::codeBitratePicRateInfo(TComBitRatePicRateInfo *info, Int tempLevelLow, Int tempLevelHigh)
-{
-  for(Int i = tempLevelLow; i <= tempLevelHigh; i++)
-  {
-    WRITE_FLAG( info->getBitRateInfoPresentFlag(i),  "bit_rate_info_present_flag[i]" );
-    WRITE_FLAG( info->getPicRateInfoPresentFlag(i),  "pic_rate_info_present_flag[i]" );
-    if(info->getBitRateInfoPresentFlag(i))
-    {
-      WRITE_CODE( info->getAvgBitRate(i), 16, "avg_bit_rate[i]" );
-      WRITE_CODE( info->getMaxBitRate(i), 16, "max_bit_rate[i]" );
-    }
-    if(info->getPicRateInfoPresentFlag(i))
-    {
-      WRITE_CODE( info->getConstantPicRateIdc(i),  2, "constant_pic_rate_idc[i]" );
-      WRITE_CODE( info->getAvgPicRate(i),         16, "avg_pic_rate[i]"          );
-    }
-  }
-}
-#endif  
+    }
+
 /**
  - write wavefront substreams sizes for the slice header.
@@ -1545,9 +1419,5 @@
   for (UInt idx=0; idx<numEntryPointOffsets; idx++)
   {
-#if L0116_ENTRY_POINT
     WRITE_CODE(entryPointOffset[ idx ]-1, offsetLenMinus1+1, "entry_point_offset_minus1");
-#else
-    WRITE_CODE(entryPointOffset[ idx ], offsetLenMinus1+1, "entry_point_offset");
-#endif
   }
 
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCavlc.h
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCavlc.h	(revision 534)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCavlc.h	(revision 537)
@@ -94,7 +94,4 @@
   Void  codePTL                 ( TComPTL* pcPTL, Bool profilePresentFlag, Int maxNumSubLayersMinus1);
   Void  codeProfileTier         ( ProfileTierLevel* ptl );
-#if SIGNAL_BITRATE_PICRATE_IN_VPS
-  Void codeBitratePicRateInfo(TComBitRatePicRateInfo *info, Int tempLevelLow, Int tempLevelHigh);
-#endif
   Void  codeHrdParameters       ( TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1 );
   Void  codeTilesWPPEntryPoint( TComSlice* pSlice );
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCfg.h	(revision 534)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCfg.h	(revision 537)
@@ -135,10 +135,8 @@
   Level::Tier   m_levelTier;
   Level::Name   m_level;
-#if L0046_CONSTRAINT_FLAGS
   Bool m_progressiveSourceFlag;
   Bool m_interlacedSourceFlag;
   Bool m_nonPackedConstraintFlag;
   Bool m_frameOnlyConstraintFlag;
-#endif
 
   //====== Coding Structure ========
@@ -177,7 +175,5 @@
   Int       m_loopFilterTcOffsetDiv2;
   Bool      m_DeblockingFilterControlPresent;
-#if L0386_DB_METRIC
   Bool      m_DeblockingFilterMetric;
-#endif
   Bool      m_bUseSAO;
   Int       m_maxNumOffsetsPerPic;
@@ -210,12 +206,7 @@
   Bool      m_bUseASR;
   Bool      m_bUseHADME;
-#if !L0034_COMBINED_LIST_CLEANUP
-  Bool      m_bUseLComb;
-#endif
   Bool      m_useRDOQ;
   Bool      m_useRDOQTS;
-#if L0232_RD_PENALTY
   UInt      m_rdPenalty;
-#endif
   Bool      m_bUseFastEnc;
   Bool      m_bUseEarlyCU;
@@ -258,5 +249,4 @@
   Int       m_pictureTimingSEIEnabled;
   Int       m_recoveryPointSEIEnabled;
-#if J0149_TONE_MAPPING_SEI
   Bool      m_toneMappingInfoSEIEnabled;
   Int       m_toneMapId;
@@ -284,5 +274,4 @@
   Int*      m_codedPivotValue;
   Int*      m_targetPivotValue;
-#endif
   Int       m_framePackingSEIEnabled;
   Int       m_framePackingSEIType;
@@ -294,10 +283,6 @@
   Int       m_gradualDecodingRefreshInfoEnabled;
   Int       m_decodingUnitInfoSEIEnabled;
-#if L0208_SOP_DESCRIPTION_SEI
   Int       m_SOPDescriptionSEIEnabled;
-#endif
-#if K0180_SCALABLE_NESTING_SEI
   Int       m_scalableNestingSEIEnabled;
-#endif
   //====== Weighted Prediction ========
   Bool      m_useWeightedPred;       //< Use of Weighting Prediction (P_SLICE)
@@ -312,5 +297,9 @@
   Bool      m_RCEnableRateControl;
   Int       m_RCTargetBitrate;
+#if M0036_RC_IMPROVEMENT
+  Int       m_RCKeepHierarchicalBit;
+#else
   Bool      m_RCKeepHierarchicalBit;
+#endif
   Bool      m_RCLCULevelRC;
   Bool      m_RCUseLCUSeparateModel;
@@ -389,5 +378,4 @@
   Double    m_dLambdaScaleVSO;
   UInt      m_uiVSOMode;
-  
   // LGE_WVSO_A0119
   Bool      m_bUseWVSO;
@@ -395,19 +383,15 @@
   Int       m_iVSDWeight;
   Int       m_iDWeight;
-#endif
-
   // SAIT_VSO_EST_A0033
   Bool      m_bUseEstimatedVSD; 
   Double    m_dDispCoeff;
-
+#endif
 #if H_3D_ARP
   UInt      m_uiUseAdvResPred;
   UInt      m_uiARPStepNum;
 #endif
-
 #if H_3D_IC
   Bool      m_bUseIC;
 #endif
-
   //====== Depth Intra Modes ======
 #if H_3D_DIM
@@ -417,7 +401,5 @@
   Bool      m_useDLT;
 #endif
-
-#endif
-
+#endif
 public:
   TEncCfg()
@@ -519,7 +501,5 @@
   Void      setLoopFilterTcOffset           ( Int   i )      { m_loopFilterTcOffsetDiv2    = i; }
   Void      setDeblockingFilterControlPresent ( Bool b ) { m_DeblockingFilterControlPresent = b; }
-#if L0386_DB_METRIC
   Void      setDeblockingFilterMetric       ( Bool  b )      { m_DeblockingFilterMetric = b; }
-#endif
 
   //====== Motion search ========
@@ -576,7 +556,5 @@
   Int       getLoopFilterTcOffset           ()      { return m_loopFilterTcOffsetDiv2; }
   Bool      getDeblockingFilterControlPresent()  { return  m_DeblockingFilterControlPresent; }
-#if L0386_DB_METRIC
   Bool      getDeblockingFilterMetric       ()      { return m_DeblockingFilterMetric; }
-#endif
 
   //==== Motion search ========
@@ -596,12 +574,7 @@
   Void      setUseASR                       ( Bool  b )     { m_bUseASR     = b; }
   Void      setUseHADME                     ( Bool  b )     { m_bUseHADME   = b; }
-#if !L0034_COMBINED_LIST_CLEANUP
-  Void      setUseLComb                     ( Bool  b )     { m_bUseLComb   = b; }
-#endif
   Void      setUseRDOQ                      ( Bool  b )     { m_useRDOQ    = b; }
   Void      setUseRDOQTS                    ( Bool  b )     { m_useRDOQTS  = b; }
-#if L0232_RD_PENALTY
   Void      setRDpenalty                 ( UInt  b )     { m_rdPenalty  = b; }
-#endif
   Void      setUseFastEnc                   ( Bool  b )     { m_bUseFastEnc = b; }
   Void      setUseEarlyCU                   ( Bool  b )     { m_bUseEarlyCU = b; }
@@ -620,12 +593,7 @@
   Bool      getUseASR                       ()      { return m_bUseASR;     }
   Bool      getUseHADME                     ()      { return m_bUseHADME;   }
-#if !L0034_COMBINED_LIST_CLEANUP
-  Bool      getUseLComb                     ()      { return m_bUseLComb;   }
-#endif
   Bool      getUseRDOQ                      ()      { return m_useRDOQ;    }
   Bool      getUseRDOQTS                    ()      { return m_useRDOQTS;  }
-#if L0232_RD_PENALTY
   Int      getRDpenalty                  ()      { return m_rdPenalty;  }
-#endif
   Bool      getUseFastEnc                   ()      { return m_bUseFastEnc; }
   Bool      getUseEarlyCU                   ()      { return m_bUseEarlyCU; }
@@ -719,5 +687,4 @@
   Void  setRecoveryPointSEIEnabled(Int b)                { m_recoveryPointSEIEnabled = b; }
   Int   getRecoveryPointSEIEnabled()                     { return m_recoveryPointSEIEnabled; }
-#if J0149_TONE_MAPPING_SEI
   Void  setToneMappingInfoSEIEnabled(Bool b)                 {  m_toneMappingInfoSEIEnabled = b;  }
   Bool  getToneMappingInfoSEIEnabled()                       {  return m_toneMappingInfoSEIEnabled;  }
@@ -770,5 +737,4 @@
   Void  setTMISEIExtendedWhiteLevelLumaCodeValue(Int b)      {  m_extendedWhiteLevelLumaCodeValue =b;  }
   Int   getTMISEIExtendedWhiteLevelLumaCodeValue()           {  return m_extendedWhiteLevelLumaCodeValue;  }
-#endif
   Void  setFramePackingArrangementSEIEnabled(Int b)      { m_framePackingSEIEnabled = b; }
   Int   getFramePackingArrangementSEIEnabled()           { return m_framePackingSEIEnabled; }
@@ -789,12 +755,8 @@
   Void  setDecodingUnitInfoSEIEnabled(Int b)                { m_decodingUnitInfoSEIEnabled = b;    }
   Int   getDecodingUnitInfoSEIEnabled()                     { return m_decodingUnitInfoSEIEnabled; }
-#if L0208_SOP_DESCRIPTION_SEI
   Void  setSOPDescriptionSEIEnabled(Int b)                { m_SOPDescriptionSEIEnabled = b; }
   Int   getSOPDescriptionSEIEnabled()                     { return m_SOPDescriptionSEIEnabled; }
-#endif
-#if K0180_SCALABLE_NESTING_SEI
   Void  setScalableNestingSEIEnabled(Int b)                { m_scalableNestingSEIEnabled = b; }
   Int   getScalableNestingSEIEnabled()                     { return m_scalableNestingSEIEnabled; }
-#endif
   Void      setUseWP               ( Bool b )    { m_useWeightedPred   = b;    }
   Void      setWPBiPred            ( Bool b )    { m_useWeightedBiPred = b;    }
@@ -818,6 +780,11 @@
   Int       getTargetBitrate       ()              { return m_RCTargetBitrate;       }
   Void      setTargetBitrate       ( Int bitrate ) { m_RCTargetBitrate  = bitrate;   }
+#if M0036_RC_IMPROVEMENT
+  Int       getKeepHierBit         ()              { return m_RCKeepHierarchicalBit; }
+  Void      setKeepHierBit         ( Int i )       { m_RCKeepHierarchicalBit = i;    }
+#else
   Bool      getKeepHierBit         ()              { return m_RCKeepHierarchicalBit; }
   Void      setKeepHierBit         ( Bool b )      { m_RCKeepHierarchicalBit = b;    }
+#endif
   Bool      getLCULevelRC          ()              { return m_RCLCULevelRC; }
   Void      setLCULevelRC          ( Bool b )      { m_RCLCULevelRC = b; }
@@ -916,5 +883,4 @@
   Void      setLog2MaxMvLengthVertical(Int i)             { m_log2MaxMvLengthVertical = i; }
   
-#if L0046_CONSTRAINT_FLAGS
   Bool getProgressiveSourceFlag() const { return m_progressiveSourceFlag; }
   Void setProgressiveSourceFlag(Bool b) { m_progressiveSourceFlag = b; }
@@ -928,5 +894,4 @@
   Bool getFrameOnlyConstraintFlag() const { return m_frameOnlyConstraintFlag; }
   Void setFrameOnlyConstraintFlag(Bool b) { m_frameOnlyConstraintFlag = b; }
-#endif
 #if H_3D
   /// 3D Tools 
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCu.cpp	(revision 534)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCu.cpp	(revision 537)
@@ -103,5 +103,5 @@
   
   m_bEncodeDQP = false;
-#if RATE_CONTROL_LAMBDA_DOMAIN
+#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
   m_LCUPredictionSAD = 0;
   m_addSADDepth      = 0;
@@ -256,5 +256,5 @@
   m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() );
 
-#if RATE_CONTROL_LAMBDA_DOMAIN
+#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
   m_addSADDepth      = 0;
   m_LCUPredictionSAD = 0;
@@ -592,5 +592,5 @@
     }
 
-#if RATE_CONTROL_LAMBDA_DOMAIN
+#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
     if ( uiDepth <= m_addSADDepth )
     {
@@ -862,5 +862,5 @@
   {
     bBoundary = true;
-#if RATE_CONTROL_LAMBDA_DOMAIN
+#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
     m_addSADDepth++;
 #endif
@@ -1348,4 +1348,121 @@
 }
 
+#if RATE_CONTROL_INTRA
+Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg) 
+{
+  Int k, i, j, jj;
+  Int diff[64], m1[8][8], m2[8][8], m3[8][8], iSumHad = 0;
+
+  for( k = 0; k < 64; k += 8 )
+  {
+    diff[k+0] = piOrg[0] ;
+    diff[k+1] = piOrg[1] ;
+    diff[k+2] = piOrg[2] ;
+    diff[k+3] = piOrg[3] ;
+    diff[k+4] = piOrg[4] ;
+    diff[k+5] = piOrg[5] ;
+    diff[k+6] = piOrg[6] ;
+    diff[k+7] = piOrg[7] ;
+ 
+    piOrg += iStrideOrg;
+  }
+  
+  //horizontal
+  for (j=0; j < 8; j++)
+  {
+    jj = j << 3;
+    m2[j][0] = diff[jj  ] + diff[jj+4];
+    m2[j][1] = diff[jj+1] + diff[jj+5];
+    m2[j][2] = diff[jj+2] + diff[jj+6];
+    m2[j][3] = diff[jj+3] + diff[jj+7];
+    m2[j][4] = diff[jj  ] - diff[jj+4];
+    m2[j][5] = diff[jj+1] - diff[jj+5];
+    m2[j][6] = diff[jj+2] - diff[jj+6];
+    m2[j][7] = diff[jj+3] - diff[jj+7];
+    
+    m1[j][0] = m2[j][0] + m2[j][2];
+    m1[j][1] = m2[j][1] + m2[j][3];
+    m1[j][2] = m2[j][0] - m2[j][2];
+    m1[j][3] = m2[j][1] - m2[j][3];
+    m1[j][4] = m2[j][4] + m2[j][6];
+    m1[j][5] = m2[j][5] + m2[j][7];
+    m1[j][6] = m2[j][4] - m2[j][6];
+    m1[j][7] = m2[j][5] - m2[j][7];
+    
+    m2[j][0] = m1[j][0] + m1[j][1];
+    m2[j][1] = m1[j][0] - m1[j][1];
+    m2[j][2] = m1[j][2] + m1[j][3];
+    m2[j][3] = m1[j][2] - m1[j][3];
+    m2[j][4] = m1[j][4] + m1[j][5];
+    m2[j][5] = m1[j][4] - m1[j][5];
+    m2[j][6] = m1[j][6] + m1[j][7];
+    m2[j][7] = m1[j][6] - m1[j][7];
+  }
+  
+  //vertical
+  for (i=0; i < 8; i++)
+  {
+    m3[0][i] = m2[0][i] + m2[4][i];
+    m3[1][i] = m2[1][i] + m2[5][i];
+    m3[2][i] = m2[2][i] + m2[6][i];
+    m3[3][i] = m2[3][i] + m2[7][i];
+    m3[4][i] = m2[0][i] - m2[4][i];
+    m3[5][i] = m2[1][i] - m2[5][i];
+    m3[6][i] = m2[2][i] - m2[6][i];
+    m3[7][i] = m2[3][i] - m2[7][i];
+    
+    m1[0][i] = m3[0][i] + m3[2][i];
+    m1[1][i] = m3[1][i] + m3[3][i];
+    m1[2][i] = m3[0][i] - m3[2][i];
+    m1[3][i] = m3[1][i] - m3[3][i];
+    m1[4][i] = m3[4][i] + m3[6][i];
+    m1[5][i] = m3[5][i] + m3[7][i];
+    m1[6][i] = m3[4][i] - m3[6][i];
+    m1[7][i] = m3[5][i] - m3[7][i];
+    
+    m2[0][i] = m1[0][i] + m1[1][i];
+    m2[1][i] = m1[0][i] - m1[1][i];
+    m2[2][i] = m1[2][i] + m1[3][i];
+    m2[3][i] = m1[2][i] - m1[3][i];
+    m2[4][i] = m1[4][i] + m1[5][i];
+    m2[5][i] = m1[4][i] - m1[5][i];
+    m2[6][i] = m1[6][i] + m1[7][i];
+    m2[7][i] = m1[6][i] - m1[7][i];
+  }
+  
+  for (i = 0; i < 8; i++)
+  {
+    for (j = 0; j < 8; j++)
+    {
+      iSumHad += abs(m2[i][j]);
+    }
+  }
+  iSumHad -= abs(m2[0][0]);
+  iSumHad =(iSumHad+2)>>2;
+  return(iSumHad);
+}
+
+Int  TEncCu::updateLCUDataISlice(TComDataCU* pcCU, Int LCUIdx, Int width, Int height)
+{
+  Int  xBl, yBl; 
+  const Int iBlkSize = 8;
+
+  Pel* pOrgInit   = pcCU->getPic()->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
+  Int  iStrideOrig = pcCU->getPic()->getPicYuvOrg()->getStride();
+  Pel  *pOrg;
+
+  Int iSumHad = 0;
+  for ( yBl=0; (yBl+iBlkSize)<=height; yBl+= iBlkSize)
+  {
+    for ( xBl=0; (xBl+iBlkSize)<=width; xBl+= iBlkSize)
+    {
+      pOrg = pOrgInit + iStrideOrig*yBl + xBl; 
+      iSumHad += xCalcHADs8x8_ISlice(pOrg, iStrideOrig);
+    }
+  }
+  return(iSumHad);
+}
+#endif
+
 /** check RD costs for a CU block encoded with merge
  * \param rpcBestCU
@@ -1360,5 +1477,5 @@
   UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
 #else
-  TComMvField  cMvFieldNeighbours[MRG_MAX_NUM_CANDS << 1]; // double length for mv of both lists
+  TComMvField  cMvFieldNeighbours[2 * MRG_MAX_NUM_CANDS]; // double length for mv of both lists
   UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
 #endif
@@ -1400,5 +1517,5 @@
   Int mergeCandBuffer[MRG_MAX_NUM_CANDS];
 #endif
-  for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui )
+for( UInt ui = 0; ui < numValidMergeCand; ++ui )
   {
     mergeCandBuffer[ui] = 0;
@@ -1430,6 +1547,5 @@
   {
     for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
-    {
-      {
+    {      
 #if H_3D_IC
         if( rpcTempCU->getSlice()->getApplyIC() && rpcTempCU->getSlice()->getIcSkipParseFlag() )
@@ -1443,5 +1559,4 @@
         if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1))
         {
-
         if( !(bestIsSkip && uiNoResidual == 0) )
         {
@@ -1487,5 +1602,4 @@
        m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
        // estimate residual and encode everything
-
 #if H_3D_VSO //M2
        if( m_pcRdCost->getUseRenModel() )
@@ -1498,5 +1612,4 @@
        }
 #endif
-
        m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU,
          m_ppcOrigYuv    [uhDepth],
@@ -1508,13 +1621,11 @@
 
 
-       if(uiNoResidual==0)
-       {
-         if(rpcTempCU->getQtRootCbf(0) == 0)
+          if ( uiNoResidual == 0 && rpcTempCU->getQtRootCbf(0) == 0 )
          {
+            // If no residual when allowing for one, then set mark to not try case where residual is forced to 0
            mergeCandBuffer[uiMergeCand] = 1;
          }
-       }
-
-       rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth );
+
+          rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth );
           Int orgQP = rpcTempCU->getQP( 0 );
           xCheckDQP( rpcTempCU );
@@ -1522,11 +1633,8 @@
           rpcTempCU->initEstData( uhDepth, orgQP );
 
-
       if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip )
       {
         bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0;
       }
-
-    }
     }
    }
@@ -1689,5 +1797,5 @@
 #endif
 
-#if RATE_CONTROL_LAMBDA_DOMAIN
+#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
   if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
   {
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCu.h
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCu.h	(revision 534)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncCu.h	(revision 537)
@@ -102,5 +102,5 @@
   Bool                    m_bUseSBACRD;
   TEncRateCtrl*           m_pcRateCtrl;
-#if RATE_CONTROL_LAMBDA_DOMAIN
+#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
   UInt                    m_LCUPredictionSAD;
   Int                     m_addSADDepth;
@@ -124,6 +124,9 @@
   
   Void setBitCounter        ( TComBitCounter* pcBitCounter ) { m_pcBitCounter = pcBitCounter; }
-#if RATE_CONTROL_LAMBDA_DOMAIN
+#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
   UInt getLCUPredictionSAD() { return m_LCUPredictionSAD; }
+#endif
+#if RATE_CONTROL_INTRA
+  Int   updateLCUDataISlice ( TComDataCU* pcCU, Int LCUIdx, Int width, Int height );
 #endif
 protected:
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 534)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 537)
@@ -94,10 +94,6 @@
   m_cpbRemovalDelay   = 0;
   m_lastBPSEI         = 0;
-#if L0045_NON_NESTED_SEI_RESTRICTIONS
   xResetNonNestedSEIPresentFlags();
-#if K0180_SCALABLE_NESTING_SEI
   xResetNestedSEIPresentFlags();
-#endif
-#endif
 #if H_MV
   m_layerId      = 0;
@@ -163,8 +159,6 @@
   SEIActiveParameterSets *seiActiveParameterSets = new SEIActiveParameterSets(); 
   seiActiveParameterSets->activeVPSId = m_pcCfg->getVPS()->getVPSId(); 
-#if L0047_APS_FLAGS
   seiActiveParameterSets->m_fullRandomAccessFlag = false;
   seiActiveParameterSets->m_noParamSetUpdateFlag = false;
-#endif
   seiActiveParameterSets->numSpsIdsMinus1 = 0;
   seiActiveParameterSets->activeSeqParamSetId.resize(seiActiveParameterSets->numSpsIdsMinus1 + 1); 
@@ -179,7 +173,5 @@
   seiFramePacking->m_arrangementCancelFlag = 0;
   seiFramePacking->m_arrangementType = m_pcCfg->getFramePackingArrangementSEIType();
-#if L0444_FPA_TYPE
   assert((seiFramePacking->m_arrangementType > 2) && (seiFramePacking->m_arrangementType < 6) );
-#endif
   seiFramePacking->m_quincunxSamplingFlag = m_pcCfg->getFramePackingArrangementSEIQuincunx();
   seiFramePacking->m_contentInterpretationType = m_pcCfg->getFramePackingArrangementSEIInterpretation();
@@ -195,9 +187,5 @@
   seiFramePacking->m_frame1GridPositionY = 0;
   seiFramePacking->m_arrangementReservedByte = 0;
-#if L0045_PERSISTENCE_FLAGS
   seiFramePacking->m_arrangementPersistenceFlag = true;
-#else
-  seiFramePacking->m_arrangementRepetetionPeriod = 1;
-#endif
   seiFramePacking->m_upsampledAspectRatio = 0;
   return seiFramePacking;
@@ -214,5 +202,4 @@
 }
 
-#if J0149_TONE_MAPPING_SEI
 SEIToneMappingInfo*  TEncGOP::xCreateSEIToneMappingInfo()
 {
@@ -225,5 +212,5 @@
   assert(seiToneMappingInfo->m_codedDataBitDepth >= 8 && seiToneMappingInfo->m_codedDataBitDepth <= 14);
   seiToneMappingInfo->m_targetBitDepth = m_pcCfg->getTMISEITargetBitDepth();
-  assert( (seiToneMappingInfo->m_targetBitDepth >= 1 && seiToneMappingInfo->m_targetBitDepth <= 17) || (seiToneMappingInfo->m_targetBitDepth  == 255) );
+  assert( seiToneMappingInfo->m_targetBitDepth >= 1 && seiToneMappingInfo->m_targetBitDepth <= 17 );
   seiToneMappingInfo->m_modelId = m_pcCfg->getTMISEIModelID();
   assert(seiToneMappingInfo->m_modelId >=0 &&seiToneMappingInfo->m_modelId<=4);
@@ -300,5 +287,5 @@
   return seiToneMappingInfo;
 }
-#endif
+
 Void TEncGOP::xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps)
 {
@@ -315,7 +302,5 @@
     accessUnit.push_back(new NALUnitEBSP(nalu));
     delete sei;
-#if L0045_NON_NESTED_SEI_RESTRICTIONS
     m_activeParameterSetSEIPresentInAU = true;
-#endif
   }
 
@@ -342,5 +327,4 @@
     delete sei;
   }
-#if J0149_TONE_MAPPING_SEI
   if(m_pcCfg->getToneMappingInfoSEIEnabled())
   {
@@ -354,5 +338,4 @@
     delete sei;
   }
-#endif
 }
 
@@ -389,8 +372,5 @@
 #endif
   SEIPictureTiming pictureTimingSEI;
-#if L0208_SOP_DESCRIPTION_SEI
   Bool writeSOP = m_pcCfg->getSOPDescriptionSEIEnabled();
-#endif
-#if K0180_SCALABLE_NESTING_SEI
   // Initialize Scalable Nesting SEI with single layer values
   SEIScalableNesting scalableNestingSEI;
@@ -403,8 +383,5 @@
   scalableNestingSEI.m_nestingLayerId[0]             = 0;
   scalableNestingSEI.m_callerOwnsSEIs                = true;
-#endif
-#if L0044_DU_DPB_OUTPUT_DELAY_HRD
   Int picSptDpbOutputDuDelay = 0;
-#endif
   UInt *accumBitsDU = NULL;
   UInt *accumNalsDU = NULL;
@@ -596,5 +573,5 @@
     pcSlice->getRPS()->setNumberOfLongtermPictures(0);
 
-#if FIX1071 && H_MV_FIX1071
+#if FIX1071
     if ((pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) || (pcSlice->isIRAP()))
     {
@@ -772,18 +749,4 @@
     }
 #endif
-#if !L0034_COMBINED_LIST_CLEANUP
-    if (pcSlice->getSliceType() != B_SLICE || !pcSlice->getSPS()->getUseLComb())
-    {
-      pcSlice->setNumRefIdx(REF_PIC_LIST_C, 0);
-      pcSlice->setRefPicListCombinationFlag(false);
-      pcSlice->setRefPicListModificationFlagLC(false);
-    }
-    else
-    {
-      pcSlice->setRefPicListCombinationFlag(pcSlice->getSPS()->getUseLComb());
-      pcSlice->setNumRefIdx(REF_PIC_LIST_C, pcSlice->getNumRefIdx(REF_PIC_LIST_0));
-    }
-#endif
-
     if (pcSlice->getSliceType() == B_SLICE)
     {
@@ -820,31 +783,5 @@
     pcSlice->setRefPOCList();
 
-#if L0034_COMBINED_LIST_CLEANUP
     pcSlice->setList1IdxToList0Idx();
-#else
-    pcSlice->setNoBackPredFlag( false );
-    if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag())
-    {
-      if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) )
-      {
-        pcSlice->setNoBackPredFlag( true );
-        Int i;
-        for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ )
-        {
-          if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) 
-          {
-            pcSlice->setNoBackPredFlag( false );
-            break;
-          }
-        }
-      }
-    }
-
-    if(pcSlice->getNoBackPredFlag())
-    {
-      pcSlice->setNumRefIdx(REF_PIC_LIST_C, 0);
-    }
-    pcSlice->generateCombinedList();
-#endif
 #if H_3D_TMVP
     if(pcSlice->getLayerId())
@@ -943,5 +880,4 @@
 
 #if RATE_CONTROL_LAMBDA_DOMAIN
-    Int sliceQP              = pcSlice->getSliceQp();
     Double lambda            = 0.0;
     Int actualHeadBits       = 0;
@@ -959,7 +895,7 @@
       estimatedBits = m_pcRateCtrl->getRCPic()->getTargetBits();
 
+      Int sliceQP = m_pcCfg->getInitialQP();
       if ( ( pcSlice->getPOC() == 0 && m_pcCfg->getInitialQP() > 0 ) || ( frameLevel == 0 && m_pcCfg->getForceIntraQP() ) ) // QP is specified
       {
-        sliceQP              = m_pcCfg->getInitialQP();
         Int    NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
         Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames );
@@ -972,8 +908,15 @@
       else if ( frameLevel == 0 )   // intra case, but use the model
       {
+#if RATE_CONTROL_INTRA
+        m_pcSliceEncoder->calCostSliceI(pcPic);
+#endif
         if ( m_pcCfg->getIntraPeriod() != 1 )   // do not refine allocated bits for all intra case
         {
           Int bits = m_pcRateCtrl->getRCSeq()->getLeftAverageBits();
+#if RATE_CONTROL_INTRA
+          bits = m_pcRateCtrl->getRCPic()->getRefineBitsForIntra( bits );
+#else
           bits = m_pcRateCtrl->getRCSeq()->getRefineBitsForIntra( bits );
+#endif
           if ( bits < 200 )
           {
@@ -984,5 +927,10 @@
 
         list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList();
+#if RATE_CONTROL_INTRA
+        m_pcRateCtrl->getRCPic()->getLCUInitTargetBits();
+        lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType());
+#else
         lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture );
+#endif
         sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture );
       }
@@ -990,5 +938,9 @@
       {
         list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList();
+#if RATE_CONTROL_INTRA
+        lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType());
+#else
         lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture );
+#endif
         sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture );
       }
@@ -1199,10 +1151,8 @@
     Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag();
     m_pcLoopFilter->setCfg(bLFCrossTileBoundary);
-#if L0386_DB_METRIC
     if ( m_pcCfg->getDeblockingFilterMetric() )
     {
       dblMetric(pcPic, uiNumSlices);
     }
-#endif
     m_pcLoopFilter->loopFilterPic( pcPic );
 
@@ -1267,5 +1217,5 @@
         UInt maxCU = m_pcCfg->getSliceArgument() >> ( pcSlice->getSPS()->getMaxCUDepth() << 1);
         UInt numDU = ( m_pcCfg->getSliceMode() == 1 ) ? ( pcPic->getNumCUsInFrame() / maxCU ) : ( 0 );
-        if( pcPic->getNumCUsInFrame() % maxCU != 0 )
+        if( pcPic->getNumCUsInFrame() % maxCU != 0 || numDU == 0 )
         {
           numDU ++;
@@ -1307,5 +1257,4 @@
     }
 
-#if L0208_SOP_DESCRIPTION_SEI
     if (writeSOP) // write SOP description SEI (if enabled) at the beginning of GOP
     {
@@ -1345,5 +1294,4 @@
       writeSOP = false;
     }
-#endif
 
     if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) &&
@@ -1377,5 +1325,4 @@
       pictureTimingSEI.m_auCpbRemovalDelay = std::max<Int>(1, m_totalCoded - m_lastBPSEI); // Syntax element signalled as minus, hence the .
       pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pcSlice->getPOC() - m_totalCoded;
-#if L0044_DU_DPB_OUTPUT_DELAY_HRD
       Int factor = pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2;
       pictureTimingSEI.m_picDpbOutputDuDelay = factor * pictureTimingSEI.m_picDpbOutputDelay;
@@ -1384,5 +1331,4 @@
         picSptDpbOutputDuDelay = factor * pictureTimingSEI.m_picDpbOutputDelay;
       }
-#endif
     }
 
@@ -1404,9 +1350,5 @@
       sei_buffering_period.m_initialCpbRemovalDelayOffset[0][1]     = uiInitialCpbRemovalDelay;
 
-#if L0043_TIMING_INFO
       Double dTmp = (Double)pcSlice->getSPS()->getVuiParameters()->getTimingInfo()->getNumUnitsInTick() / (Double)pcSlice->getSPS()->getVuiParameters()->getTimingInfo()->getTimeScale();
-#else
-      Double dTmp = (Double)pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNumUnitsInTick() / (Double)pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTimeScale();
-#endif
 
       UInt uiTmp = (UInt)( dTmp * 90000.0 ); 
@@ -1419,18 +1361,13 @@
 
       sei_buffering_period.m_rapCpbParamsPresentFlag              = 0;
-#if L0328_SPLICING
       //for the concatenation, it can be set to one during splicing.
       sei_buffering_period.m_concatenationFlag = 0;
       //since the temporal layer HRD is not ready, we assumed it is fixed
       sei_buffering_period.m_auCpbRemovalDelayDelta = 1;
-#endif
-#if L0044_CPB_DPB_DELAY_OFFSET
       sei_buffering_period.m_cpbDelayOffset = 0;
       sei_buffering_period.m_dpbDelayOffset = 0;
-#endif
 
       m_seiWriter.writeSEImessage( nalu.m_Bitstream, sei_buffering_period, pcSlice->getSPS());
       writeRBSPTrailingBits(nalu.m_Bitstream);
-#if L0045_NON_NESTED_SEI_RESTRICTIONS
       {
       UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
@@ -1444,9 +1381,5 @@
       m_bufferingPeriodSEIPresentInAU = true;
       }
-#else
-      accessUnit.push_back(new NALUnitEBSP(nalu));
-#endif
-
-#if K0180_SCALABLE_NESTING_SEI
+
       if (m_pcCfg->getScalableNestingSEIEnabled())
       {
@@ -1458,5 +1391,4 @@
         m_seiWriter.writeSEImessage( naluTmp.m_Bitstream, scalableNestingSEI, pcSlice->getSPS());
         writeRBSPTrailingBits(naluTmp.m_Bitstream);
-#if L0045_NON_NESTED_SEI_RESTRICTIONS
         UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
         UInt offsetPosition = m_activeParameterSetSEIPresentInAU + m_bufferingPeriodSEIPresentInAU + m_pictureTimingSEIPresentInAU;   // Insert BP SEI after non-nested APS, BP and PT SEIs
@@ -1468,9 +1400,5 @@
         accessUnit.insert(it, new NALUnitEBSP(naluTmp));
         m_nestedBufferingPeriodSEIPresentInAU = true;
-#else
-        accessUnit.push_back(new NALUnitEBSP(naluTmp));
-#endif
-      }
-#endif
+      }
 
       m_lastBPSEI = m_totalCoded;
@@ -1935,5 +1863,7 @@
       if ( m_pcCfg->getUseRateCtrl() )
       {
+#if !M0036_RC_IMPROVEMENT
         Double effectivePercentage = m_pcRateCtrl->getRCPic()->getEffectivePercentage();
+#endif
         Double avgQP     = m_pcRateCtrl->getRCPic()->calAverageQP();
         Double avgLambda = m_pcRateCtrl->getRCPic()->calAverageLambda();
@@ -1942,5 +1872,13 @@
           avgLambda = lambda;
         }
+#if M0036_RC_IMPROVEMENT
+#if RATE_CONTROL_INTRA
+        m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, pcSlice->getSliceType());
+#else
+        m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda );
+#endif
+#else
         m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, effectivePercentage );
+#endif
         m_pcRateCtrl->getRCPic()->addToPictureLsit( m_pcRateCtrl->getPicList() );
 
@@ -1962,4 +1900,5 @@
       }
 #endif
+
       if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) &&
           ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) &&
@@ -1996,9 +1935,5 @@
             for( i = ( numDU - 2 ); i >= 0; i -- )
             {
-#if L0043_TIMING_INFO
               ui64Tmp = ( ( ( accumBitsDU[ numDU - 1 ]  - accumBitsDU[ i ] ) * ( vui->getTimingInfo()->getTimeScale() / vui->getTimingInfo()->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) );
-#else
-              ui64Tmp = ( ( ( accumBitsDU[ numDU - 1 ]  - accumBitsDU[ i ] ) * ( hrd->getTimeScale() / hrd->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) );
-#endif
               if( (UInt)ui64Tmp > maxDiff )
               {
@@ -2012,9 +1947,5 @@
             {
               flag = 0;
-#if L0043_TIMING_INFO
               ui64Tmp = ( ( ( accumBitsDU[ numDU - 1 ]  - accumBitsDU[ i ] ) * ( vui->getTimingInfo()->getTimeScale() / vui->getTimingInfo()->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) );
-#else
-              ui64Tmp = ( ( ( accumBitsDU[ numDU - 1 ]  - accumBitsDU[ i ] ) * ( hrd->getTimeScale() / hrd->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) );
-#endif
 
               if( (UInt)ui64Tmp > maxDiff )
@@ -2048,5 +1979,4 @@
           m_seiWriter.writeSEImessage(nalu.m_Bitstream, pictureTimingSEI, pcSlice->getSPS());
           writeRBSPTrailingBits(nalu.m_Bitstream);
-#if L0045_NON_NESTED_SEI_RESTRICTIONS
           UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
           UInt offsetPosition = m_activeParameterSetSEIPresentInAU 
@@ -2059,10 +1989,5 @@
           accessUnit.insert(it, new NALUnitEBSP(nalu));
           m_pictureTimingSEIPresentInAU = true;
-#else
-          AccessUnit::iterator it = find_if(accessUnit.begin(), accessUnit.end(), mem_fun(&NALUnit::isSlice));
-          accessUnit.insert(it, new NALUnitEBSP(nalu));
-#endif
-        }
-#if K0180_SCALABLE_NESTING_SEI
+        }
           if ( m_pcCfg->getScalableNestingSEIEnabled() ) // put picture timing SEI into scalable nesting SEI
           {
@@ -2073,5 +1998,4 @@
             m_seiWriter.writeSEImessage(nalu.m_Bitstream, scalableNestingSEI, pcSlice->getSPS());
             writeRBSPTrailingBits(nalu.m_Bitstream);
-#if L0045_NON_NESTED_SEI_RESTRICTIONS
             UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
             UInt offsetPosition = m_activeParameterSetSEIPresentInAU 
@@ -2084,11 +2008,5 @@
             accessUnit.insert(it, new NALUnitEBSP(nalu));
             m_nestedPictureTimingSEIPresentInAU = true;
-#else
-            AccessUnit::iterator it = find_if(accessUnit.begin(), accessUnit.end(), mem_fun(&NALUnit::isSlice));
-            accessUnit.insert(it, new NALUnitEBSP(nalu));
-#endif
           }
-#endif
-
         }
         if( m_pcCfg->getDecodingUnitInfoSEIEnabled() && hrd->getSubPicCpbParamsPresentFlag() )
@@ -2102,8 +2020,6 @@
             tempSEI.m_decodingUnitIdx = i;
             tempSEI.m_duSptCpbRemovalDelay = pictureTimingSEI.m_duCpbRemovalDelayMinus1[i] + 1;
-#if L0044_DU_DPB_OUTPUT_DELAY_HRD
             tempSEI.m_dpbOutputDuDelayPresentFlag = false;
             tempSEI.m_picSptDpbOutputDuDelay = picSptDpbOutputDuDelay;
-#endif
 
             AccessUnit::iterator it;
@@ -2115,5 +2031,4 @@
               writeRBSPTrailingBits(nalu.m_Bitstream);
 
-#if L0045_NON_NESTED_SEI_RESTRICTIONS
               UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit);
               UInt offsetPosition = m_activeParameterSetSEIPresentInAU 
@@ -2125,8 +2040,4 @@
               }
               accessUnit.insert(it, new NALUnitEBSP(nalu));
-#else
-              it = find_if(accessUnit.begin(), accessUnit.end(), mem_fun(&NALUnit::isSlice));
-              accessUnit.insert(it, new NALUnitEBSP(nalu)); 
-#endif
             }
             else
@@ -2154,10 +2065,6 @@
         }
       }
-#if L0045_NON_NESTED_SEI_RESTRICTIONS
       xResetNonNestedSEIPresentFlags();
-#if K0180_SCALABLE_NESTING_SEI
       xResetNestedSEIPresentFlags();
-#endif
-#endif
       pcPic->getPicYuvRec()->copyToPic(pcPicYuvRecOut);
 
@@ -2851,5 +2758,4 @@
 }
 
-#if L0045_NON_NESTED_SEI_RESTRICTIONS
 /** Function for finding the position to insert the first of APS and non-nested BP, PT, DU info SEI messages.
  * \param accessUnit Access Unit of the current picture
@@ -2871,7 +2777,5 @@
   return seiStartPos;
 }
-#endif
-
-#if L0386_DB_METRIC
+
 Void TEncGOP::dblMetric( TComPic* pcPic, UInt uiNumSlices )
 {
@@ -2887,4 +2791,6 @@
   const UInt noCol = (picWidth>>log2maxTB);
   const UInt noRows = (picHeight>>log2maxTB);
+  assert(noCol > 1);
+  assert(noRows > 1);
   UInt64 *colSAD = (UInt64*)malloc(noCol*sizeof(UInt64));
   UInt64 *rowSAD = (UInt64*)malloc(noRows*sizeof(UInt64));
@@ -2995,5 +2901,5 @@
   free(rowSAD);
 }
-#endif
+
 #if H_MV
 Void TEncGOP::xSetRefPicListModificationsMv( TComSlice* pcSlice, UInt iGOPid )
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncGOP.h
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncGOP.h	(revision 534)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncGOP.h	(revision 537)
@@ -128,13 +128,9 @@
   UInt                    m_tl0Idx;
   UInt                    m_rapIdx;
-#if L0045_NON_NESTED_SEI_RESTRICTIONS
   Bool                    m_activeParameterSetSEIPresentInAU;
   Bool                    m_bufferingPeriodSEIPresentInAU;
   Bool                    m_pictureTimingSEIPresentInAU;
-#if K0180_SCALABLE_NESTING_SEI
   Bool                    m_nestedBufferingPeriodSEIPresentInAU;
   Bool                    m_nestedPictureTimingSEIPresentInAU;
-#endif
-#endif
 public:
   TEncGOP();
@@ -199,10 +195,7 @@
   SEIDisplayOrientation*  xCreateSEIDisplayOrientation();
 
-#if J0149_TONE_MAPPING_SEI
   SEIToneMappingInfo*     xCreateSEIToneMappingInfo();
-#endif
 
   Void xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps);
-#if L0045_NON_NESTED_SEI_RESTRICTIONS
   Int xGetFirstSeiLocation (AccessUnit &accessUnit);
   Void xResetNonNestedSEIPresentFlags()
@@ -212,5 +205,4 @@
     m_pictureTimingSEIPresentInAU      = false;
   }
-#if K0180_SCALABLE_NESTING_SEI
   Void xResetNestedSEIPresentFlags()
   {
@@ -218,12 +210,8 @@
     m_nestedPictureTimingSEIPresentInAU      = false;
   }
-#endif
-#endif
 #if H_MV
    Void  xSetRefPicListModificationsMv( TComSlice* pcSlice, UInt iGOPid );
 #endif
-#if L0386_DB_METRIC
   Void dblMetric( TComPic* pcPic, UInt uiNumSlices );
-#endif
 };// END CLASS DEFINITION TEncGOP
 
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncRateCtrl.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncRateCtrl.cpp	(revision 534)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncRateCtrl.cpp	(revision 537)
@@ -67,4 +67,8 @@
   m_bitsLeft            = 0;
   m_useLCUSeparateModel = false;
+#if M0036_RC_IMPROVEMENT
+  m_adaptiveBit         = 0;
+  m_lastLambda          = 0.0;
+#endif
 }
 
@@ -74,5 +78,9 @@
 }
 
+#if M0036_RC_IMPROVEMENT
+Void TEncRCSeq::create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel, Int adaptiveBit )
+#else
 Void TEncRCSeq::create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel )
+#endif
 {
   destroy();
@@ -101,9 +109,27 @@
     m_betaUpdate  = 0.025;
   }
-  else
+#if M0036_RC_IMPROVEMENT
+  else if ( m_seqTargetBpp < 0.2 )
   {
     m_alphaUpdate = 0.1;
     m_betaUpdate  = 0.05;
   }
+  else if ( m_seqTargetBpp < 0.5 )
+  {
+    m_alphaUpdate = 0.2;
+    m_betaUpdate  = 0.1;
+  }
+  else
+  {
+    m_alphaUpdate = 0.4;
+    m_betaUpdate  = 0.2;
+  }
+#else
+  else
+  {
+    m_alphaUpdate = 0.1;
+    m_betaUpdate  = 0.05;
+  }
+#endif
   m_averageBits     = (Int)(m_targetBits / totalFrames);
   Int picWidthInBU  = ( m_picWidth  % m_LCUWidth  ) == 0 ? m_picWidth  / m_LCUWidth  : m_picWidth  / m_LCUWidth  + 1;
@@ -146,4 +172,8 @@
   m_framesLeft = m_totalFrames;
   m_bitsLeft   = m_targetBits;
+#if M0036_RC_IMPROVEMENT
+  m_adaptiveBit = adaptiveBit;
+  m_lastLambda = 0.0;
+#endif
 }
 
@@ -203,6 +233,19 @@
     for ( Int i=0; i<m_numberOfLevel; i++ )
     {
+#if RATE_CONTROL_INTRA
+      if (i>0)
+      {
+        m_picPara[i].m_alpha = 3.2003;
+        m_picPara[i].m_beta  = -1.367;
+      }
+      else
+      {
+        m_picPara[i].m_alpha = ALPHA;   
+        m_picPara[i].m_beta  = BETA2;
+      }
+#else
       m_picPara[i].m_alpha = 3.2003;
       m_picPara[i].m_beta  = -1.367;
+#endif
     }
   }
@@ -228,6 +271,11 @@
       for ( Int j=0; j<m_numberOfLCU; j++)
       {
+#if RATE_CONTROL_INTRA
+        m_LCUPara[i][j].m_alpha = m_picPara[i].m_alpha;
+        m_LCUPara[i][j].m_beta  = m_picPara[i].m_beta;
+#else
         m_LCUPara[i][j].m_alpha = 3.2003;
         m_LCUPara[i][j].m_beta  = -1.367;
+#endif
       }
     }
@@ -251,4 +299,5 @@
 }
 
+#if !RATE_CONTROL_INTRA
 Int TEncRCSeq::getRefineBitsForIntra( Int orgBits )
 {
@@ -264,4 +313,18 @@
   return orgBits * 10;
 }
+#endif
+
+#if M0036_RC_IMPROVEMENT
+Void TEncRCSeq::setAllBitRatio( Double basicLambda, Double* equaCoeffA, Double* equaCoeffB )
+{
+  Int* bitsRatio = new Int[m_GOPSize];
+  for ( Int i=0; i<m_GOPSize; i++ )
+  {
+    bitsRatio[i] = (Int)( equaCoeffA[i] * pow( basicLambda, equaCoeffB[i] ) * m_numberOfPixel );
+  }
+  initBitsRatio( bitsRatio );
+  delete[] bitsRatio;
+}
+#endif
 
 //GOP level
@@ -286,4 +349,66 @@
   Int targetBits = xEstGOPTargetBits( encRCSeq, numPic );
 
+#if M0036_RC_IMPROVEMENT
+  if ( encRCSeq->getAdaptiveBits() > 0 && encRCSeq->getLastLambda() > 0.1 )
+  {
+    Double targetBpp = (Double)targetBits / encRCSeq->getNumPixel();
+    Double basicLambda = 0.0;
+    Double* lambdaRatio = new Double[encRCSeq->getGOPSize()];
+    Double* equaCoeffA = new Double[encRCSeq->getGOPSize()];
+    Double* equaCoeffB = new Double[encRCSeq->getGOPSize()];
+
+    if ( encRCSeq->getAdaptiveBits() == 1 )   // for GOP size =4, low delay case
+    {
+      if ( encRCSeq->getLastLambda() < 120.0 )
+      {
+        lambdaRatio[1] = 0.725 * log( encRCSeq->getLastLambda() ) + 0.5793;
+        lambdaRatio[0] = 1.3 * lambdaRatio[1];
+        lambdaRatio[2] = 1.3 * lambdaRatio[1];
+        lambdaRatio[3] = 1.0;
+      }
+      else
+      {
+        lambdaRatio[0] = 5.0;
+        lambdaRatio[1] = 4.0;
+        lambdaRatio[2] = 5.0;
+        lambdaRatio[3] = 1.0;
+      }
+    }
+    else if ( encRCSeq->getAdaptiveBits() == 2 )  // for GOP size = 8, random access case
+    {
+      if ( encRCSeq->getLastLambda() < 90.0 )
+      {
+        lambdaRatio[0] = 1.0;
+        lambdaRatio[1] = 0.725 * log( encRCSeq->getLastLambda() ) + 0.7963;
+        lambdaRatio[2] = 1.3 * lambdaRatio[1];
+        lambdaRatio[3] = 3.25 * lambdaRatio[1];
+        lambdaRatio[4] = 3.25 * lambdaRatio[1];
+        lambdaRatio[5] = 1.3  * lambdaRatio[1];
+        lambdaRatio[6] = 3.25 * lambdaRatio[1];
+        lambdaRatio[7] = 3.25 * lambdaRatio[1];
+      }
+      else
+      {
+        lambdaRatio[0] = 1.0;
+        lambdaRatio[1] = 4.0;
+        lambdaRatio[2] = 5.0;
+        lambdaRatio[3] = 12.3;
+        lambdaRatio[4] = 12.3;
+        lambdaRatio[5] = 5.0;
+        lambdaRatio[6] = 12.3;
+        lambdaRatio[7] = 12.3;
+      }
+    }
+
+    xCalEquaCoeff( encRCSeq, lambdaRatio, equaCoeffA, equaCoeffB, encRCSeq->getGOPSize() );
+    basicLambda = xSolveEqua( targetBpp, equaCoeffA, equaCoeffB, encRCSeq->getGOPSize() );
+    encRCSeq->setAllBitRatio( basicLambda, equaCoeffA, equaCoeffB );
+
+    delete []lambdaRatio;
+    delete []equaCoeffA;
+    delete []equaCoeffB;
+  }
+#endif
+
   m_picTargetBitInGOP = new Int[numPic];
   Int i;
@@ -297,5 +422,9 @@
   {
     currPicRatio = encRCSeq->getBitRatio( i );
+#if M0036_RC_IMPROVEMENT
+    m_picTargetBitInGOP[i] = (Int)( ((Double)targetBits) * currPicRatio / totalPicRatio );
+#else
     m_picTargetBitInGOP[i] = targetBits * currPicRatio / totalPicRatio;
+#endif
   }
 
@@ -306,4 +435,52 @@
   m_bitsLeft     = m_targetBits;
 }
+
+#if M0036_RC_IMPROVEMENT
+Void TEncRCGOP::xCalEquaCoeff( TEncRCSeq* encRCSeq, Double* lambdaRatio, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize )
+{
+  for ( Int i=0; i<GOPSize; i++ )
+  {
+    Int frameLevel = encRCSeq->getGOPID2Level(i);
+    Double alpha   = encRCSeq->getPicPara(frameLevel).m_alpha;
+    Double beta    = encRCSeq->getPicPara(frameLevel).m_beta;
+    equaCoeffA[i] = pow( 1.0/alpha, 1.0/beta ) * pow( lambdaRatio[i], 1.0/beta );
+    equaCoeffB[i] = 1.0/beta;
+  }
+}
+
+Double TEncRCGOP::xSolveEqua( Double targetBpp, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize )
+{
+  Double solution = 100.0;
+  Double minNumber = 0.1;
+  Double maxNumber = 10000.0;
+  for ( Int i=0; i<g_RCIterationNum; i++ )
+  { 
+    Double fx = 0.0;
+    for ( Int j=0; j<GOPSize; j++ )
+    {
+      fx += equaCoeffA[j] * pow( solution, equaCoeffB[j] );
+    }
+
+    if ( fabs( fx - targetBpp ) < 0.000001 )
+    {
+      break;
+    }
+
+    if ( fx > targetBpp )
+    {
+      minNumber = solution;
+      solution = ( solution + maxNumber ) / 2.0;
+    }
+    else
+    {
+      maxNumber = solution;
+      solution = ( solution + minNumber ) / 2.0;
+    }
+  }
+
+  solution = Clip3( 0.1, 10000.0, solution );
+  return solution;
+}
+#endif
 
 Void TEncRCGOP::destroy()
@@ -357,7 +534,11 @@
 
   m_LCUs         = NULL;
+#if !M0036_RC_IMPROVEMENT
   m_lastPicture  = NULL;
+#endif
   m_picActualHeaderBits = 0;
+#if !M0036_RC_IMPROVEMENT
   m_totalMAD            = 0.0;
+#endif
   m_picActualBits       = 0;
   m_picQP               = 0;
@@ -384,5 +565,9 @@
   }
 
+#if M0036_RC_IMPROVEMENT
+  targetBits  = Int( ((Double)GOPbitsLeft) * currPicRatio / totalPicRatio );
+#else
   targetBits  = Int( GOPbitsLeft * currPicRatio / totalPicRatio );
+#endif
 
   if ( targetBits < 100 )
@@ -480,5 +665,9 @@
       m_LCUs[LCUIdx].m_lambda     = 0.0;
       m_LCUs[LCUIdx].m_targetBits = 0;
+#if M0036_RC_IMPROVEMENT
+      m_LCUs[LCUIdx].m_bitWeight  = 1.0;
+#else
       m_LCUs[LCUIdx].m_MAD        = 0.0;
+#endif
       Int currWidth  = ( (i == picWidthInLCU -1) ? picWidth  - LCUWidth *(picWidthInLCU -1) : LCUWidth  );
       Int currHeight = ( (j == picHeightInLCU-1) ? picHeight - LCUHeight*(picHeightInLCU-1) : LCUHeight );
@@ -487,9 +676,12 @@
   }
   m_picActualHeaderBits = 0;
+#if !M0036_RC_IMPROVEMENT
   m_totalMAD            = 0.0;
+#endif
   m_picActualBits       = 0;
   m_picQP               = 0;
   m_picLambda           = 0.0;
 
+#if !M0036_RC_IMPROVEMENT
   m_lastPicture = NULL;
   list<TEncRCPic*>::reverse_iterator it;
@@ -502,4 +694,5 @@
     }
   }
+#endif
 }
 
@@ -515,10 +708,28 @@
 }
 
+
+#if RATE_CONTROL_INTRA
+Double TEncRCPic::estimatePicLambda( list<TEncRCPic*>& listPreviousPictures, SliceType eSliceType)
+#else
 Double TEncRCPic::estimatePicLambda( list<TEncRCPic*>& listPreviousPictures )
+#endif
 {
   Double alpha         = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
   Double beta          = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
   Double bpp       = (Double)m_targetBits/(Double)m_numberOfPixel;
+#if RATE_CONTROL_INTRA
+  Double estLambda;
+  if (eSliceType == I_SLICE)
+  {
+    estLambda = calculateLambdaIntra(alpha, beta, pow(m_totalCostIntra/(Double)m_numberOfPixel, BETA1), bpp); 
+  }
+  else
+  {
+    estLambda = alpha * pow( bpp, beta );
+  }
+#else
   Double estLambda = alpha * pow( bpp, beta );
+#endif  
+  
   Double lastLevelLambda = -1.0;
   Double lastPicLambda   = -1.0;
@@ -566,4 +777,42 @@
 
   m_estPicLambda = estLambda;
+
+#if M0036_RC_IMPROVEMENT
+  Double totalWeight = 0.0;
+  // initial BU bit allocation weight
+  for ( Int i=0; i<m_numberOfLCU; i++ )
+  {
+#if RC_FIX
+    Double alphaLCU, betaLCU;
+    if ( m_encRCSeq->getUseLCUSeparateModel() )
+    {
+      alphaLCU = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_alpha;
+      betaLCU  = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_beta;
+    }
+    else
+    {
+      alphaLCU = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
+      betaLCU  = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
+    }
+#else
+    Double alphaLCU = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_alpha;
+    Double betaLCU  = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_beta;
+#endif
+
+    m_LCUs[i].m_bitWeight =  m_LCUs[i].m_numberOfPixel * pow( estLambda/alphaLCU, 1.0/betaLCU );
+
+    if ( m_LCUs[i].m_bitWeight < 0.01 )
+    {
+      m_LCUs[i].m_bitWeight = 0.01;
+    }
+    totalWeight += m_LCUs[i].m_bitWeight;
+  }
+  for ( Int i=0; i<m_numberOfLCU; i++ )
+  {
+    Double BUTargetBits = m_targetBits * m_LCUs[i].m_bitWeight / totalWeight;
+    m_LCUs[i].m_bitWeight = BUTargetBits;
+  }
+#endif
+
   return estLambda;
 }
@@ -607,12 +856,47 @@
 }
 
+#if RATE_CONTROL_INTRA
+Double TEncRCPic::getLCUTargetBpp(SliceType eSliceType)  
+#else 
 Double TEncRCPic::getLCUTargetBpp()
+#endif
 {
   Int   LCUIdx    = getLCUCoded();
   Double bpp      = -1.0;
   Int avgBits     = 0;
+#if !M0036_RC_IMPROVEMENT
   Double totalMAD = -1.0;
   Double MAD      = -1.0;
-
+#endif
+
+#if RATE_CONTROL_INTRA
+  if (eSliceType == I_SLICE){
+    Int noOfLCUsLeft = m_numberOfLCU - LCUIdx + 1;
+    Int bitrateWindow = min(4,noOfLCUsLeft);
+    Double MAD      = getLCU(LCUIdx).m_costIntra;
+
+    if (m_remainingCostIntra > 0.1 )
+    {
+      Double weightedBitsLeft = (m_bitsLeft*bitrateWindow+(m_bitsLeft-getLCU(LCUIdx).m_targetBitsLeft)*noOfLCUsLeft)/(Double)bitrateWindow;
+      avgBits = Int( MAD*weightedBitsLeft/m_remainingCostIntra );
+    }
+    else
+    {
+      avgBits = Int( m_bitsLeft / m_LCULeft );
+    }
+    m_remainingCostIntra -= MAD;
+  }
+  else
+  {
+#endif
+#if M0036_RC_IMPROVEMENT
+  Double totalWeight = 0;
+  for ( Int i=LCUIdx; i<m_numberOfLCU; i++ )
+  {
+    totalWeight += m_LCUs[i].m_bitWeight;
+  }
+  Int realInfluenceLCU = min( g_RCLCUSmoothWindowSize, getLCULeft() );
+  avgBits = (Int)( m_LCUs[LCUIdx].m_bitWeight - ( totalWeight - m_bitsLeft ) / realInfluenceLCU + 0.5 );
+#else
   if ( m_lastPicture == NULL )
   {
@@ -637,16 +921,13 @@
     }
   }
-
-#if L0033_RC_BUGFIX
+#endif
+#if RATE_CONTROL_INTRA
+  }
+#endif
+
   if ( avgBits < 1 )
   {
     avgBits = 1;
   }
-#else
-  if ( avgBits < 5 )
-  {
-    avgBits = 5;
-  }
-#endif
 
   bpp = ( Double )avgBits/( Double )m_LCUs[ LCUIdx ].m_numberOfPixel;
@@ -716,9 +997,5 @@
   //for Lambda clip, LCU level clip
   Int clipNeighbourQP = g_RCInvalidQPValue;
-#if L0033_RC_BUGFIX
   for ( int i=LCUIdx - 1; i>=0; i-- )
-#else
-  for ( int i=LCUIdx; i>=0; i-- )
-#endif
   {
     if ( (getLCU(i)).m_QP > g_RCInvalidQPValue )
@@ -773,6 +1050,11 @@
     beta  *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 );
 
+#if M0036_RC_IMPROVEMENT
+    alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
+    beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
+#else
     alpha = Clip3( 0.05, 20.0, alpha );
     beta  = Clip3( -3.0, -0.1, beta  );
+#endif
 
     TRCParameter rcPara;
@@ -787,9 +1069,18 @@
   alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha;
   double lnbpp = log( bpp );
+#if M0036_RC_IMPROVEMENT
+  lnbpp = Clip3( -5.0, -0.1, lnbpp );
+#else
   lnbpp = Clip3( -5.0, 1.0, lnbpp );
+#endif
   beta  += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp;
 
+#if M0036_RC_IMPROVEMENT
+  alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
+  beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
+#else
   alpha = Clip3( 0.05, 20.0, alpha );
   beta  = Clip3( -3.0, -0.1, beta  );
+#endif
   TRCParameter rcPara;
   rcPara.m_alpha = alpha;
@@ -799,4 +1090,5 @@
 }
 
+#if !M0036_RC_IMPROVEMENT
 Double TEncRCPic::getEffectivePercentage()
 {
@@ -816,4 +1108,5 @@
   return effectivePixelPercentage;
 }
+#endif
 
 Double TEncRCPic::calAverageQP()
@@ -871,5 +1164,13 @@
 }
 
+#if M0036_RC_IMPROVEMENT
+#if RATE_CONTROL_INTRA
+Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, SliceType eSliceType)
+#else
+Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda )
+#endif
+#else
 Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, Double effectivePercentage )
+#endif
 {
   m_picActualHeaderBits = actualHeaderBits;
@@ -884,12 +1185,21 @@
   }
   m_picLambda           = averageLambda;
+#if !M0036_RC_IMPROVEMENT
   for ( Int i=0; i<m_numberOfLCU; i++ )
   {
     m_totalMAD += m_LCUs[i].m_MAD;
   }
+#endif
 
   Double alpha = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
   Double beta  = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
-
+#if RATE_CONTROL_INTRA
+  if (eSliceType == I_SLICE)
+  {
+    updateAlphaBetaIntra(&alpha, &beta);
+  }
+  else
+  {
+#endif
   // update parameters
   Double picActualBits = ( Double )m_picActualBits;
@@ -898,11 +1208,20 @@
   Double inputLambda   = m_picLambda;
 
+#if M0036_RC_IMPROVEMENT
+  if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 )
+#else
   if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 || effectivePercentage < 0.05 )
+#endif
   {
     alpha *= ( 1.0 - m_encRCSeq->getAlphaUpdate() / 2.0 );
     beta  *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 );
 
+#if M0036_RC_IMPROVEMENT
+    alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
+    beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
+#else
     alpha = Clip3( 0.05, 20.0, alpha );
     beta  = Clip3( -3.0, -0.1, beta  );
+#endif
     TRCParameter rcPara;
     rcPara.m_alpha = alpha;
@@ -916,9 +1235,21 @@
   alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha;
   double lnbpp = log( picActualBpp );
+#if M0036_RC_IMPROVEMENT
+  lnbpp = Clip3( -5.0, -0.1, lnbpp );
+#else
   lnbpp = Clip3( -5.0, 1.0, lnbpp );
+#endif
   beta  += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp;
 
+#if M0036_RC_IMPROVEMENT
+  alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
+  beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
+#else
   alpha = Clip3( 0.05, 20.0, alpha );
   beta  = Clip3( -3.0, -0.1, beta  );
+#endif
+#if RATE_CONTROL_INTRA
+  }
+#endif
 
   TRCParameter rcPara;
@@ -927,5 +1258,105 @@
 
   m_encRCSeq->setPicPara( m_frameLevel, rcPara );
-}
+
+#if M0036_RC_IMPROVEMENT
+  if ( m_frameLevel == 1 )
+  {
+    Double currLambda = Clip3( 0.1, 10000.0, m_picLambda );
+    Double updateLastLambda = g_RCWeightHistoryLambda * m_encRCSeq->getLastLambda() + g_RCWeightCurrentLambda * currLambda;
+    m_encRCSeq->setLastLambda( updateLastLambda );
+  }
+#endif
+}
+
+#if RATE_CONTROL_INTRA
+Int TEncRCPic::getRefineBitsForIntra( Int orgBits )
+{
+  Double alpha=0.25, beta=0.5582;
+  Int iIntraBits;
+
+  if (orgBits*40 < m_numberOfPixel)
+  {
+    alpha=0.25;
+  }
+  else
+  {
+    alpha=0.30;
+  }
+
+  iIntraBits = (Int)(alpha* pow(m_totalCostIntra*4.0/(Double)orgBits, beta)*(Double)orgBits+0.5);
+  
+  return iIntraBits;
+}
+
+Double TEncRCPic::calculateLambdaIntra(double alpha, double beta, double MADPerPixel, double bitsPerPixel)
+{
+  return ( (alpha/256.0) * pow( MADPerPixel/bitsPerPixel, beta ) );
+}
+
+Void TEncRCPic::updateAlphaBetaIntra(double *alpha, double *beta)
+{
+  Double lnbpp = log(pow(m_totalCostIntra / (Double)m_numberOfPixel, BETA1));
+  Double diffLambda = (*beta)*(log((Double)m_picActualBits)-log((Double)m_targetBits));
+
+  diffLambda = Clip3(-0.125, 0.125, 0.25*diffLambda);
+  *alpha    =  (*alpha) * exp(diffLambda);
+  *beta     =  (*beta) + diffLambda / lnbpp;
+}
+
+
+Void TEncRCPic::getLCUInitTargetBits()  
+{
+  Int iAvgBits     = 0;
+
+  m_remainingCostIntra = m_totalCostIntra;
+  for (Int i=m_numberOfLCU-1; i>=0; i--)
+  {
+    iAvgBits += Int(m_targetBits * getLCU(i).m_costIntra/m_totalCostIntra);
+    getLCU(i).m_targetBitsLeft = iAvgBits;
+  }
+}
+
+
+Double TEncRCPic::getLCUEstLambdaAndQP(Double bpp, Int clipPicQP, Int *estQP) 
+{
+  Int   LCUIdx = getLCUCoded();
+
+  Double   alpha = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
+  Double   beta  = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
+
+  Double costPerPixel = getLCU(LCUIdx).m_costIntra/(Double)getLCU(LCUIdx).m_numberOfPixel;
+  costPerPixel = pow(costPerPixel, BETA1);
+  Double estLambda = calculateLambdaIntra(alpha, beta, costPerPixel, bpp);
+
+  Int clipNeighbourQP = g_RCInvalidQPValue;
+  for (int i=LCUIdx-1; i>=0; i--)
+  {
+    if ((getLCU(i)).m_QP > g_RCInvalidQPValue)
+    {
+      clipNeighbourQP = getLCU(i).m_QP;
+      break;
+    }
+  }
+
+  Int minQP = clipPicQP - 2;
+  Int maxQP = clipPicQP + 2;
+
+  if ( clipNeighbourQP > g_RCInvalidQPValue )
+  {
+    maxQP = min(clipNeighbourQP + 1, maxQP); 
+    minQP = max(clipNeighbourQP - 1, minQP); 
+  }
+
+  Double maxLambda=exp(((Double)(maxQP+0.49)-13.7122)/4.2005);
+  Double minLambda=exp(((Double)(minQP-0.49)-13.7122)/4.2005);
+
+  estLambda = Clip3(minLambda, maxLambda, estLambda);
+
+  *estQP = Int( 4.2005 * log(estLambda) + 13.7122 + 0.5 );
+  *estQP = Clip3(minQP, maxQP, *estQP);
+
+  return estLambda;
+}
+#endif
 
 TEncRateCtrl::TEncRateCtrl()
@@ -961,5 +1392,9 @@
 }
 
+#if M0036_RC_IMPROVEMENT
+Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP] )
+#else
 Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP] )
+#endif
 {
   destroy();
@@ -976,5 +1411,10 @@
 
   Int numberOfLevel = 1;
+#if M0036_RC_IMPROVEMENT
+  Int adaptiveBit = 0;
+  if ( keepHierBits > 0 )
+#else
   if ( keepHierBits )
+#endif
   {
     numberOfLevel = Int( log((Double)GOPSize)/log(2.0) + 0.5 ) + 1;
@@ -998,5 +1438,10 @@
     }
   }
+
+#if M0036_RC_IMPROVEMENT
+  if ( keepHierBits > 0 )
+#else
   if ( keepHierBits )
+#endif
   {
     Double bpp = (Double)( targetBitrate / (Double)( frameRate*picWidth*picHeight ) );
@@ -1031,4 +1476,10 @@
         bitsRatio[3] = 14;
       }
+#if M0036_RC_IMPROVEMENT
+      if ( keepHierBits == 2 )
+      {
+        adaptiveBit = 1;
+      }
+#endif
     }
     else if ( GOPSize == 8 && !isLowdelay )
@@ -1078,8 +1529,18 @@
         bitsRatio[7] = 1;
       }
+#if M0036_RC_IMPROVEMENT
+      if ( keepHierBits == 2 )
+      {
+        adaptiveBit = 2;
+      }
+#endif
     }
     else
     {
+#if M0036_RC_IMPROVEMENT
+      printf( "\n hierarchical bit allocation is not support for the specified coding structure currently.\n" );
+#else
       printf( "\n hierarchical bit allocation is not support for the specified coding structure currently." );
+#endif
     }
   }
@@ -1094,5 +1555,9 @@
     }
   }
+#if M0036_RC_IMPROVEMENT
+  if ( keepHierBits > 0 )
+#else
   if ( keepHierBits )
+#endif
   {
     if ( GOPSize == 4 && isLowdelay )
@@ -1129,5 +1594,9 @@
 
   m_encRCSeq = new TEncRCSeq;
+#if M0036_RC_IMPROVEMENT
+  m_encRCSeq->create( totalFrames, targetBitrate, frameRate, GOPSize, picWidth, picHeight, LCUWidth, LCUHeight, numberOfLevel, useLCUSeparateModel, adaptiveBit );
+#else
   m_encRCSeq->create( totalFrames, targetBitrate, frameRate, GOPSize, picWidth, picHeight, LCUWidth, LCUHeight, numberOfLevel, useLCUSeparateModel );
+#endif
   m_encRCSeq->initBitsRatio( bitsRatio );
   m_encRCSeq->initGOPID2Level( GOPID2Level );
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncRateCtrl.h
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncRateCtrl.h	(revision 534)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncRateCtrl.h	(revision 537)
@@ -65,4 +65,20 @@
 const Double g_RCWeightPicTargetBitInGOP    = 0.9;
 const Double g_RCWeightPicRargetBitInBuffer = 1.0 - g_RCWeightPicTargetBitInGOP;
+#if M0036_RC_IMPROVEMENT
+const Int g_RCIterationNum = 20;
+const Double g_RCWeightHistoryLambda = 0.5;
+const Double g_RCWeightCurrentLambda = 1.0 - g_RCWeightHistoryLambda;
+const Int g_RCLCUSmoothWindowSize = 4;
+const Double g_RCAlphaMinValue = 0.05;
+const Double g_RCAlphaMaxValue = 500.0;
+const Double g_RCBetaMinValue  = -3.0;
+const Double g_RCBetaMaxValue  = -0.1;
+#endif
+
+#if RATE_CONTROL_INTRA
+#define ALPHA     6.7542;
+#define BETA1     1.2517
+#define BETA2     1.7860
+#endif
 
 struct TRCLCU
@@ -72,6 +88,14 @@
   Int m_targetBits;
   Double m_lambda;
+#if M0036_RC_IMPROVEMENT
+  Double m_bitWeight;
+#else
   Double m_MAD;
+#endif
   Int m_numberOfPixel;
+#if RATE_CONTROL_INTRA
+  Double m_costIntra;
+  Int m_targetBitsLeft;
+#endif
 };
 
@@ -89,5 +113,9 @@
 
 public:
+#if M0036_RC_IMPROVEMENT
+  Void create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel, Int adaptiveBit );
+#else
   Void create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel );
+#endif
   Void destroy();
   Void initBitsRatio( Int bitsRatio[] );
@@ -96,5 +124,10 @@
   Void initLCUPara( TRCParameter** LCUPara = NULL );    // NULL to initial with default value
   Void updateAfterPic ( Int bits );
+#if !RATE_CONTROL_INTRA
   Int  getRefineBitsForIntra( Int orgBits );
+#endif
+#if M0036_RC_IMPROVEMENT
+  Void setAllBitRatio( Double basicLambda, Double* equaCoeffA, Double* equaCoeffB );
+#endif
 
 public:
@@ -134,4 +167,10 @@
   Double getBetaUpdate()                { return m_betaUpdate; }
 
+#if M0036_RC_IMPROVEMENT
+  Int    getAdaptiveBits()              { return m_adaptiveBit;  }
+  Double getLastLambda()                { return m_lastLambda;   }
+  Void   setLastLambda( Double lamdba ) { m_lastLambda = lamdba; }
+#endif
+
 private:
   Int m_totalFrames;
@@ -160,4 +199,9 @@
   Double m_betaUpdate;
   Bool m_useLCUSeparateModel;
+
+#if M0036_RC_IMPROVEMENT
+  Int m_adaptiveBit;
+  Double m_lastLambda;
+#endif
 };
 
@@ -175,4 +219,8 @@
 private:
   Int  xEstGOPTargetBits( TEncRCSeq* encRCSeq, Int GOPSize );
+#if M0036_RC_IMPROVEMENT
+  Void   xCalEquaCoeff( TEncRCSeq* encRCSeq, Double* lambdaRatio, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize );
+  Double xSolveEqua( Double targetBpp, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize );
+#endif
 
 public:
@@ -203,15 +251,38 @@
   Void destroy();
 
+#if !RATE_CONTROL_INTRA
   Double estimatePicLambda( list<TEncRCPic*>& listPreviousPictures );
+#endif
   Int    estimatePicQP    ( Double lambda, list<TEncRCPic*>& listPreviousPictures );
+#if RATE_CONTROL_INTRA
+  Int    getRefineBitsForIntra(Int orgBits);
+  Double calculateLambdaIntra(double alpha, double beta, double MADPerPixel, double bitsPerPixel);
+  Double estimatePicLambda( list<TEncRCPic*>& listPreviousPictures, SliceType eSliceType);
+
+  Void   updateAlphaBetaIntra(double *alpha, double *beta);
+
+  Double getLCUTargetBpp(SliceType eSliceType);
+  Double getLCUEstLambdaAndQP(Double bpp, Int clipPicQP, Int *estQP);
+#else
   Double getLCUTargetBpp();
+#endif
   Double getLCUEstLambda( Double bpp );
   Int    getLCUEstQP( Double lambda, Int clipPicQP );
 
   Void updateAfterLCU( Int LCUIdx, Int bits, Int QP, Double lambda, Bool updateLCUParameter = true );
+#if M0036_RC_IMPROVEMENT
+#if RATE_CONTROL_INTRA
+  Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, SliceType eSliceType);
+#else
+  Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda );
+#endif
+#else
   Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, Double effectivePercentage );
+#endif
 
   Void addToPictureLsit( list<TEncRCPic*>& listPreviousPictures );
+#if !M0036_RC_IMPROVEMENT
   Double getEffectivePercentage();
+#endif
   Double calAverageQP();
   Double calAverageLambda();
@@ -229,5 +300,7 @@
   Int  getNumberOfLCU()                                   { return m_numberOfLCU; }
   Int  getTargetBits()                                    { return m_targetBits; }
+#if !RATE_CONTROL_INTRA 
   Void setTargetBits( Int bits )                          { m_targetBits = bits; }
+#endif
   Int  getEstHeaderBits()                                 { return m_estHeaderBits; }
   Int  getLCULeft()                                       { return m_LCULeft; }
@@ -239,6 +312,14 @@
   TRCLCU& getLCU( Int LCUIdx )                            { return m_LCUs[LCUIdx]; }
   Int  getPicActualHeaderBits()                           { return m_picActualHeaderBits; }
+#if !M0036_RC_IMPROVEMENT
   Double getTotalMAD()                                    { return m_totalMAD; }
   Void   setTotalMAD( Double MAD )                        { m_totalMAD = MAD; }
+#endif
+#if RATE_CONTROL_INTRA
+  Void setTargetBits( Int bits )                          { m_targetBits = bits; m_bitsLeft = bits;}
+  Void setTotalIntraCost(Double cost)                     { m_totalCostIntra = cost; }
+  Void getLCUInitTargetBits();
+#endif
+
   Int  getPicActualBits()                                 { return m_picActualBits; }
   Int  getPicActualQP()                                   { return m_picQP; }
@@ -267,9 +348,17 @@
   TRCLCU* m_LCUs;
   Int m_picActualHeaderBits;    // only SH and potential APS
+#if !M0036_RC_IMPROVEMENT
   Double m_totalMAD;
+#endif
+#if RATE_CONTROL_INTRA
+  Double m_totalCostIntra; 
+  Double m_remainingCostIntra;
+#endif
   Int m_picActualBits;          // the whole picture, including header
   Int m_picQP;                  // in integer form
   Double m_picLambda;
+#if !M0036_RC_IMPROVEMENT
   TEncRCPic* m_lastPicture;
+#endif
 };
 
@@ -281,5 +370,9 @@
 
 public:
+#if M0036_RC_IMPROVEMENT
+  Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] );
+#else
   Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] );
+#endif
   Void destroy();
   Void initRCPic( Int frameLevel );
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	(revision 534)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp	(revision 537)
@@ -299,5 +299,7 @@
         m_iTypePartBest[iPartIdx] = -1;
         if( m_bUseSBACRD )
+        {
           m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] );
+        }
       }
     }
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 534)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 537)
@@ -1067,5 +1067,4 @@
     }
 #endif
-
     // save prediction 
     if(default0Save1Load2 == 1)
@@ -1427,6 +1426,6 @@
 #if H_3D_DIM_ENC
                                 , Bool        zeroResi
-#endif
-                                )
+#endif                                
+)
 {
   UInt    uiFullDepth   = pcCU->getDepth( 0 ) +  uiTrDepth;
@@ -1436,5 +1435,4 @@
   
 #if HHI_RQT_INTRA_SPEEDUP
-#if L0232_RD_PENALTY
   Int maxTuSize = pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize();
   Int isIntraSlice = (pcCU->getSlice()->getSliceType() == I_SLICE);
@@ -1453,12 +1451,8 @@
   }
   if( bCheckFirst && noSplitIntraMaxTuSize )
+  {
+    bCheckSplit = false;
+  }
 #else
-  if( bCheckFirst && bCheckFull )
-#endif
-  {
-    bCheckSplit = false;
-  }
-#else
-#if L0232_RD_PENALTY
   Int maxTuSize = pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize();
   Int isIntraSlice = (pcCU->getSlice()->getSliceType() == I_SLICE);
@@ -1469,5 +1463,4 @@
   }
 #endif
-#endif
 #if H_3D_DIM
   if( isDimMode( pcCU->getLumaIntraDir( uiAbsPartIdx ) ) )
@@ -1476,5 +1469,4 @@
   }
 #endif
-
   Double  dSingleCost   = MAX_DOUBLE;
 #if H_3D_VSO
@@ -1667,10 +1659,8 @@
       //----- determine rate and r-d cost -----
       UInt uiSingleBits = xGetIntraBitsQT( pcCU, uiTrDepth, uiAbsPartIdx, true, !bLumaOnly, false );
-#if L0232_RD_PENALTY
       if(m_pcEncCfg->getRDpenalty() && (uiLog2TrSize==5) && !isIntraSlice)
       {
         uiSingleBits=uiSingleBits*4; 
       }
-#endif
 #if H_3D_VSO // M40
       if ( m_pcRdCost->getUseLambdaScaleVSO())      
@@ -1823,5 +1813,4 @@
     }
   }
-
 #if H_3D_VSO // M42
   if ( m_pcRdCost->getUseRenModel() && bCheckFull )
@@ -1836,5 +1825,4 @@
   }
 #endif
-
   ruiDistY += uiSingleDistY;
   ruiDistC += uiSingleDistC;
@@ -2788,6 +2776,4 @@
         
         UInt   iModeBits = xModeBitsIntra( pcCU, uiMode, uiPU, uiPartOffset, uiDepth, uiInitTrDepth );
-
-      
 #if H_3D_VSO // M35
 #if H_3D_VSO_FIX // This fix should be enabled after verification 
@@ -2924,5 +2910,4 @@
     }
 #endif
-
     //===== check modes (using r-d costs) =====
 #if HHI_RQT_INTRA_SPEEDUP_MOD
@@ -3112,5 +3097,4 @@
       UInt   uiPUDistC = 0;
       Double dPUCost   = 0.0;
-
 #if H_3D_VSO // M37
       // reset Model
@@ -3164,6 +3148,5 @@
     {
 #endif
-    
-    //--- update transform index and cbf ---
+        //--- update transform index and cbf ---
     UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth(0) + uiInitTrDepth ) << 1 );
     ::memcpy( pcCU->getTransformIdx()       + uiPartOffset, m_puhQTTempTrIdx,  uiQPartNum * sizeof( UChar ) );
@@ -3764,10 +3747,8 @@
     UInt          uiBitsTempL0[MAX_NUM_REF];
 
-#if L0034_COMBINED_LIST_CLEANUP
     TComMv        mvValidList1;
     Int           refIdxValidList1 = 0;
     UInt          bitsValidList1 = MAX_UINT;
     UInt          costValidList1 = MAX_UINT;
-#endif
 
     xGetBlkBits( ePartSize, pcCU->getSlice()->isInterP(), iPartIdx, uiLastMode, uiMbBits);
@@ -3821,10 +3802,5 @@
         uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdx[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS];
 #if ZERO_MVD_EST
-#if L0034_COMBINED_LIST_CLEANUP
         if ( iRefList == 0 || pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) < 0 )
-#else
-        if ((iRefList != 1 || !pcCU->getSlice()->getNoBackPredFlag()) &&
-            (pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) <= 0 || pcCU->getSlice()->getRefIdxOfLC(eRefPicList, iRefIdxTemp)>=0))
-#endif
         {
           uiZeroMvdBitsTemp = uiBitsTemp;
@@ -3846,5 +3822,4 @@
         
 #if GPB_SIMPLE_UNI
-#if L0034_COMBINED_LIST_CLEANUP
         if ( iRefList == 1 )    // list 1
         {
@@ -3871,47 +3846,4 @@
         }
 #else
-        if ( pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0)
-        {
-          if ( iRefList && ( pcCU->getSlice()->getNoBackPredFlag() || (pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && !pcCU->getSlice()->getNoBackPredFlag() && pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(iRefIdxTemp)>=0 ) ) )
-            {
-              if ( pcCU->getSlice()->getNoBackPredFlag() )
-              {
-                cMvTemp[1][iRefIdxTemp] = cMvTemp[0][iRefIdxTemp];
-                uiCostTemp = uiCostTempL0[iRefIdxTemp];
-                /*first subtract the bit-rate part of the cost of the other list*/
-                uiCostTemp -= m_pcRdCost->getCost( uiBitsTempL0[iRefIdxTemp] );
-              }
-              else
-              {
-                cMvTemp[1][iRefIdxTemp] = cMvTemp[0][pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(iRefIdxTemp)]; 
-                uiCostTemp = uiCostTempL0[pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(iRefIdxTemp)];
-                /*first subtract the bit-rate part of the cost of the other list*/
-                uiCostTemp -= m_pcRdCost->getCost( uiBitsTempL0[pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(iRefIdxTemp)] );
-              }
-              /*correct the bit-rate part of the current ref*/
-              m_pcRdCost->setPredictor  ( cMvPred[iRefList][iRefIdxTemp] );
-              uiBitsTemp += m_pcRdCost->getBits( cMvTemp[1][iRefIdxTemp].getHor(), cMvTemp[1][iRefIdxTemp].getVer() );
-              /*calculate the correct cost*/
-              uiCostTemp += m_pcRdCost->getCost( uiBitsTemp );
-            }
-            else
-            {
-              xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
-            }
-        }
-        else
-        {
-          if (iRefList && pcCU->getSlice()->getNoBackPredFlag())
-          {
-            uiCostTemp = MAX_UINT;
-            cMvTemp[1][iRefIdxTemp] = cMvTemp[0][iRefIdxTemp];
-          }
-          else
-          { 
-            xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
-          }        
-        }
-#endif
-#else
         xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
 #endif
@@ -3919,5 +3851,4 @@
         xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPred[iRefList][iRefIdxTemp], aaiMvpIdx[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp);
 
-#if L0034_COMBINED_LIST_CLEANUP
         if ( iRefList == 0 )
         {
@@ -3944,55 +3875,4 @@
           refIdxValidList1 = iRefIdxTemp;
         }
-#else
-        if(pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && !pcCU->getSlice()->getNoBackPredFlag())
-        {
-          if(iRefList==REF_PIC_LIST_0)
-          {
-            uiCostTempL0[iRefIdxTemp] = uiCostTemp;
-            uiBitsTempL0[iRefIdxTemp] = uiBitsTemp;
-            if(pcCU->getSlice()->getRefIdxOfLC(REF_PIC_LIST_0, iRefIdxTemp)<0)
-            {
-              uiCostTemp = MAX_UINT;
-            }
-          }
-          else
-          {
-            if(pcCU->getSlice()->getRefIdxOfLC(REF_PIC_LIST_1, iRefIdxTemp)<0)
-            {
-              uiCostTemp = MAX_UINT;
-            }           
-          }
-        }
-
-        if ( ( iRefList == 0 && uiCostTemp < uiCost[iRefList] ) ||
-            ( iRefList == 1 &&  pcCU->getSlice()->getNoBackPredFlag() && iRefIdxTemp == iRefIdx[0] ) ||
-            ( iRefList == 1 && (pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0) && (iRefIdxTemp==0 || iRefIdxTemp == iRefIdx[0]) && !pcCU->getSlice()->getNoBackPredFlag() && (iRefIdxTemp == pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(iRefIdxTemp)) ) ||
-            ( iRefList == 1 && !pcCU->getSlice()->getNoBackPredFlag() && uiCostTemp < uiCost[iRefList] ) )
-          {
-            uiCost[iRefList] = uiCostTemp;
-            uiBits[iRefList] = uiBitsTemp; // storing for bi-prediction
-            
-            // set motion
-            cMv[iRefList]     = cMvTemp[iRefList][iRefIdxTemp];
-            iRefIdx[iRefList] = iRefIdxTemp;
-            pcCU->getCUMvField(eRefPicList)->setAllMv( cMv[iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
-            pcCU->getCUMvField(eRefPicList)->setAllRefIdx( iRefIdx[iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
-
-            if(!pcCU->getSlice()->getMvdL1ZeroFlag())
-            {
-              // storing list 1 prediction signal for iterative bi-directional prediction
-              if ( eRefPicList == REF_PIC_LIST_1 )
-              {
-                TComYuv*  pcYuvPred = &m_acYuvPred[iRefList];
-                motionCompensation ( pcCU, pcYuvPred, eRefPicList, iPartIdx );
-              }
-              if ( (pcCU->getSlice()->getNoBackPredFlag() || (pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(0)==0 )) && eRefPicList == REF_PIC_LIST_0 )
-              {
-                TComYuv*  pcYuvPred = &m_acYuvPred[iRefList];
-                motionCompensation ( pcCU, pcYuvPred, eRefPicList, iPartIdx );
-              }
-            }
-          }
-#endif
       }
     }
@@ -4058,5 +3938,4 @@
         
         Int         iRefList    = iIter % 2;
-#if L0034_COMBINED_LIST_CLEANUP
         if ( m_pcEncCfg->getUseFastEnc() )
         {
@@ -4081,10 +3960,4 @@
           motionCompensation ( pcCU, pcYuvPred, RefPicList(1-iRefList), iPartIdx );
         }
-#else
-        if ( m_pcEncCfg->getUseFastEnc() && (pcCU->getSlice()->getNoBackPredFlag() || (pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(0)==0 )) )
-        {
-          iRefList = 1;
-        }
-#endif
         RefPicList  eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
 
@@ -4221,15 +4094,8 @@
     UInt uiMEBits = 0;
     // Set Motion Field_
-#if L0034_COMBINED_LIST_CLEANUP
     cMv[1] = mvValidList1;
     iRefIdx[1] = refIdxValidList1;
     uiBits[1] = bitsValidList1;
     uiCost[1] = costValidList1;
-#else
-    if ( pcCU->getSlice()->getNoBackPredFlag() || (pcCU->getSlice()->getNumRefIdx(REF_PIC_LIST_C) > 0 && pcCU->getSlice()->getRefIdxOfL0FromRefIdxOfL1(0)==0 ) )
-    {
-      uiCost[1] = MAX_UINT;
-    }
-#endif
 #if AMP_MRG
     if (bTestNormalMC)
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 534)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 537)
@@ -475,5 +475,4 @@
 #endif
 
-#if L0386_DB_METRIC
   if ( m_pcCfg->getDeblockingFilterMetric() )
   {
@@ -483,5 +482,4 @@
     rpcSlice->setDeblockingFilterTcOffsetDiv2( 0 );
   } else
-#endif
   if (rpcSlice->getPPS()->getDeblockingFilterControlPresentFlag())
   {
@@ -560,7 +558,5 @@
   // store lambda
   slice->setSliceQp( sliceQP );
-#if L0033_RC_BUGFIX
   slice->setSliceQpBase ( sliceQP );
-#endif
   m_pcRdCost ->setLambda( lambda );
 #if WEIGHTED_CHROMA_DISTORTION
@@ -876,4 +872,40 @@
 /** \param rpcPic   picture class
  */
+#if RATE_CONTROL_INTRA
+Void TEncSlice::calCostSliceI(TComPic*& rpcPic)
+{
+  UInt    uiCUAddr;
+  UInt    uiStartCUAddr;
+  UInt    uiBoundingCUAddr;
+  Int     iSumHad, shift = g_bitDepthY-8, offset = (shift>0)?(1<<(shift-1)):0;;
+  Double  iSumHadSlice = 0;
+
+  rpcPic->getSlice(getSliceIdx())->setSliceSegmentBits(0);
+  TComSlice* pcSlice            = rpcPic->getSlice(getSliceIdx());
+  xDetermineStartAndBoundingCUAddr ( uiStartCUAddr, uiBoundingCUAddr, rpcPic, false );
+
+  UInt uiEncCUOrder;
+  uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU()); 
+  for( uiEncCUOrder = uiStartCUAddr/rpcPic->getNumPartInCU();
+       uiEncCUOrder < (uiBoundingCUAddr+(rpcPic->getNumPartInCU()-1))/rpcPic->getNumPartInCU();
+       uiCUAddr = rpcPic->getPicSym()->getCUOrderMap(++uiEncCUOrder) )
+  {
+    // initialize CU encoder
+    TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );
+    pcCU->initCU( rpcPic, uiCUAddr );
+
+    Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
+    Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
+
+    iSumHad = m_pcCuEncoder->updateLCUDataISlice(pcCU, uiCUAddr, width, height);
+
+    (m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr)).m_costIntra=(iSumHad+offset)>>shift;
+    iSumHadSlice += (m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr)).m_costIntra;
+
+  }
+  m_pcRateCtrl->getRCPic()->setTotalIntraCost(iSumHadSlice);
+}
+#endif
+
 Void TEncSlice::compressSlice( TComPic*& rpcPic )
 {
@@ -1161,5 +1193,9 @@
         Double bpp       = -1.0;
 
+#if M0036_RC_IMPROVEMENT
+        if ( ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE && m_pcCfg->getForceIntraQP() ) || !m_pcCfg->getLCULevelRC() )
+#else
         if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE || !m_pcCfg->getLCULevelRC() )
+#endif
         {
           estQP = pcSlice->getSliceQp();
@@ -1167,16 +1203,37 @@
         else
         {
+#if RATE_CONTROL_INTRA
+          bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp(pcSlice->getSliceType());
+          if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE)
+          {
+            estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambdaAndQP(bpp, pcSlice->getSliceQp(), &estQP);
+          }
+          else
+          {
+            estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );
+            estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
+          }
+#else
           bpp       = m_pcRateCtrl->getRCPic()->getLCUTargetBpp();
           estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );
           estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
+#endif
+
           estQP     = Clip3( -pcSlice->getSPS()->getQpBDOffsetY(), MAX_QP, estQP );
 
           m_pcRdCost->setLambda(estLambda);
+#if M0036_RC_IMPROVEMENT
+#if RDOQ_CHROMA_LAMBDA
+          // set lambda for RDOQ
+          Double weight=m_pcRdCost->getChromaWeight();
+          m_pcTrQuant->setLambda( estLambda, estLambda / weight );
+#else
+          m_pcTrQuant->setLambda( estLambda );
+#endif
+#endif
         }
 
         m_pcRateCtrl->setRCQP( estQP );
-#if L0033_RC_BUGFIX
         pcCU->getSlice()->setSliceQpBase( estQP );
-#endif
       }
 #endif
@@ -1185,7 +1242,9 @@
       m_pcCuEncoder->compressCU( pcCU );
 
+#if !TICKET_1090_FIX
 #if RATE_CONTROL_LAMBDA_DOMAIN
       if ( m_pcCfg->getUseRateCtrl() )
       {
+#if !M0036_RC_IMPROVEMENT
         UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
         Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
@@ -1194,4 +1253,5 @@
         MAD = MAD * MAD;
         ( m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr) ).m_MAD = MAD;
+#endif
 
         Int actualQP        = g_RCInvalidQPValue;
@@ -1217,7 +1277,12 @@
         }
         m_pcRdCost->setLambda(oldLambda);
-
+#if RATE_CONTROL_INTRA
+        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, 
+          pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
+#else
         m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );
-      }
+#endif
+      }
+#endif
 #endif
       
@@ -1253,4 +1318,50 @@
         }
       }
+
+#if TICKET_1090_FIX
+#if RATE_CONTROL_LAMBDA_DOMAIN
+      if ( m_pcCfg->getUseRateCtrl() )
+      {
+#if !M0036_RC_IMPROVEMENT
+        UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
+        Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
+        Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
+        Double MAD = (Double)SAD / (Double)(height * width);
+        MAD = MAD * MAD;
+        ( m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr) ).m_MAD = MAD;
+#endif
+
+        Int actualQP        = g_RCInvalidQPValue;
+        Double actualLambda = m_pcRdCost->getLambda();
+        Int actualBits      = pcCU->getTotalBits();
+        Int numberOfEffectivePixels    = 0;
+        for ( Int idx = 0; idx < rpcPic->getNumPartInCU(); idx++ )
+        {
+          if ( pcCU->getPredictionMode( idx ) != MODE_NONE && ( !pcCU->isSkipped( idx ) ) )
+          {
+            numberOfEffectivePixels = numberOfEffectivePixels + 16;
+            break;
+          }
+        }
+
+        if ( numberOfEffectivePixels == 0 )
+        {
+          actualQP = g_RCInvalidQPValue;
+        }
+        else
+        {
+          actualQP = pcCU->getQP( 0 );
+        }
+        m_pcRdCost->setLambda(oldLambda);
+
+#if RATE_CONTROL_INTRA
+        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, 
+          pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
+#else
+        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );
+#endif
+      }
+#endif
+#endif
     }
     // other case: encodeCU is not called
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSlice.h
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSlice.h	(revision 534)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncSlice.h	(revision 537)
@@ -131,4 +131,7 @@
   Void    precompressSlice    ( TComPic*& rpcPic                                );      ///< precompress slice for multi-loop opt.
   Void    compressSlice       ( TComPic*& rpcPic                                );      ///< analysis stage of slice
+#if RATE_CONTROL_INTRA
+  Void    calCostSliceI       ( TComPic*& rpcPic );
+#endif
   Void    encodeSlice         ( TComPic*& rpcPic, TComOutputBitstream* pcSubstreams  );
   
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncTop.cpp	(revision 534)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncTop.cpp	(revision 537)
@@ -293,13 +293,8 @@
   // This seems to be incorrect, but irrelevant for the MV-HEVC
   *(m_cVPS->getPTL()) = *m_cSPS.getPTL();
-#if L0043_TIMING_INFO
   m_cVPS->getTimingInfo()->setTimingInfoPresentFlag       ( false );
-#endif
 #else
   *m_cVPS.getPTL() = *m_cSPS.getPTL();
-
-#if L0043_TIMING_INFO
   m_cVPS.getTimingInfo()->setTimingInfoPresentFlag       ( false );
-#endif
 #endif
   // initialize PPS
@@ -532,10 +527,8 @@
   profileTierLevel.setProfileIdc(m_profile);
   profileTierLevel.setProfileCompatibilityFlag(m_profile, 1);
-#if L0046_CONSTRAINT_FLAGS
   profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag);
   profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag);
   profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag);
   profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
-#endif
   
   if (m_profile == Profile::MAIN10 && g_bitDepthY == 8 && g_bitDepthC == 8)
@@ -584,7 +577,4 @@
 
   m_cSPS.setMaxTrSize   ( 1 << m_uiQuadtreeTULog2MaxSize );
-#if !L0034_COMBINED_LIST_CLEANUP
-  m_cSPS.setUseLComb    ( m_bUseLComb           );
-#endif
   
   Int i;
@@ -651,11 +641,6 @@
     pcVUI->setFieldSeqFlag(false);
     pcVUI->setHrdParametersPresentFlag(false);
-#if L0043_TIMING_INFO
     pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag());
     pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1   (getNumTicksPocDiffOneMinus1()   );
-#else
-    pcVUI->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag());
-    pcVUI->setNumTicksPocDiffOneMinus1   (getNumTicksPocDiffOneMinus1()   );
-#endif
     pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag());
     pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag());
@@ -790,7 +775,5 @@
     }
   }
-#if L0323_LIMIT_DEFAULT_LIST_SIZE
   assert(bestPos <= 15);
-#endif
   m_cPPS.setNumRefIdxL0DefaultActive(bestPos);
   m_cPPS.setNumRefIdxL1DefaultActive(bestPos);
@@ -1047,5 +1030,4 @@
 }
 
-#if L0208_SOP_DESCRIPTION_SEI
 Int TEncTop::getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid )
 {
@@ -1077,5 +1059,4 @@
   return rpsIdx;
 }
-#endif
 
 Void  TEncTop::xInitPPSforTiles()
Index: branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncTop.h	(revision 534)
+++ branches/HTM-DEV-0.3-dev2/source/Lib/TLibEncoder/TEncTop.h	(revision 537)
@@ -188,7 +188,5 @@
   TComPPS*                getPPS                () { return  &m_cPPS;                 }
   Void selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid );
-#if L0208_SOP_DESCRIPTION_SEI
   Int getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid );
-#endif
   TComScalingList*        getScalingList        () { return  &m_scalingList;         }
 #if H_MV
