diff --git a/interface/SKP_Silk_SDK_API.h b/interface/SKP_Silk_SDK_API.h
index e266780acb3faef18a215401a9ef813a9340a8a9..e112526edb65a1652d534d1ddda4119398c4b518 100644
--- a/interface/SKP_Silk_SDK_API.h
+++ b/interface/SKP_Silk_SDK_API.h
@@ -31,6 +31,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "SKP_Silk_control.h"
 #include "SKP_Silk_typedef.h"
 #include "SKP_Silk_errors.h"
+#include "entenc.h"
+#include "entdec.h"
 
 #ifdef __cplusplus
 extern "C"
@@ -84,8 +86,8 @@ SKP_int SKP_Silk_SDK_Encode(                            /* O:   Returns error co
     const SKP_SILK_SDK_EncControlStruct *encControl,    /* I:   Control status                                  */
     const SKP_int16                     *samplesIn,     /* I:   Speech sample input vector                      */
     SKP_int                             nSamplesIn,     /* I:   Number of samples in input vector               */
-    SKP_uint8                           *outData,       /* O:   Encoded output vector                           */
-    SKP_int16                           *nBytesOut      /* I/O: Number of bytes in outData (input: Max bytes)   */
+    ec_enc                              *psRangeEnc,    /* I/O  Compressor data structure                       */
+    SKP_int16                           *nBytesOut      /* I/O: Number of bytes in payload (input: Max bytes)   */
 );
 
 /****************************************/
@@ -113,7 +115,7 @@ SKP_int SKP_Silk_SDK_Decode(                            /* O:   Returns error co
     void*                               decState,       /* I/O: State                                           */
     SKP_SILK_SDK_DecControlStruct*      decControl,     /* I/O: Control Structure                               */
     SKP_int                             lostFlag,       /* I:   0: no loss, 1 loss                              */
-    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */
+    ec_dec                              *psRangeDec,    /* I/O  Compressor data structure                       */
     const SKP_int                       nBytesIn,       /* I:   Number of input bytes                           */
     SKP_int16                           *samplesOut,    /* O:   Decoded output speech vector                    */
     SKP_int16                           *nSamplesOut    /* I/O: Number of samples (vector/decoded)              */
@@ -134,7 +136,7 @@ void SKP_Silk_SDK_search_for_LBRR(
 /* Get table of contents for a packet */
 /**************************************/
 void SKP_Silk_SDK_get_TOC(
-    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */
+    ec_dec                              *psRangeDec,    /* I/O  Compressor data structure                   */
     const SKP_int16                     nBytesIn,       /* I:   Number of input bytes                           */
     SKP_Silk_TOC_struct                 *Silk_TOC       /* O:   Table of contents                               */
 );
diff --git a/src_FLP/SKP_Silk_encode_frame_FLP.c b/src_FLP/SKP_Silk_encode_frame_FLP.c
index 8fb954a2f0b211741e82d2f89e02f257218a0fa2..62e76124565f0c2648414aeea1ebbd84136633aa 100644
--- a/src_FLP/SKP_Silk_encode_frame_FLP.c
+++ b/src_FLP/SKP_Silk_encode_frame_FLP.c
@@ -6,9 +6,9 @@
 /****************/
 SKP_int SKP_Silk_encode_frame_FLP( 
     SKP_Silk_encoder_state_FLP      *psEnc,             /* I/O  Encoder state FLP                       */
-          SKP_uint8                 *pCode,             /* O    Payload                                 */
-          SKP_int16                 *pnBytesOut,        /* I/O  Number of payload bytes;                */
+    SKP_int16                       *pnBytesOut,        /* I/O  Number of payload bytes;                */
                                                         /*      input: max length; output: used         */
+    ec_enc                          *psRangeEnc,        /* I/O  compressor data structure                */
     const SKP_int16                 *pIn                /* I    Input speech frame                      */
 )
 {
@@ -25,8 +25,6 @@ SKP_int SKP_Silk_encode_frame_FLP(
     SKP_uint8   LBRRpayload[ MAX_ARITHM_BYTES ];
     SKP_int16   nBytesLBRR;
 
-    ec_byte_buffer range_enc_celt_buf;
-
     const SKP_uint16 *FrameTermination_CDF;
 
 TIC(ENCODE_FRAME)
@@ -117,7 +115,7 @@ TOC(PROCESS_GAINS)
     /****************************************/
     nBytesLBRR = MAX_ARITHM_BYTES;
 TIC(LBRR)
-    SKP_Silk_LBRR_encode_FLP( psEnc, &sEncCtrl, LBRRpayload, &nBytesLBRR, xfw );
+    //SKP_Silk_LBRR_encode_FLP( psEnc, &sEncCtrl, LBRRpayload, &nBytesLBRR, xfw );
 TOC(LBRR)
 
     /*****************************************/
@@ -148,13 +146,9 @@ TOC(NSQ)
     }
 
     /****************************************/
-    /* Initialize arithmetic coder          */
+    /* Initialize range coder               */
     /****************************************/
     if( psEnc->sCmn.nFramesInPayloadBuf == 0 ) {
-        ec_byte_writeinit_buffer( &range_enc_celt_buf, psEnc->sCmn.sRC.buffer, MAX_ARITHM_BYTES );
-        ec_enc_init( &psEnc->sCmn.sRC.range_enc_celt_state, &range_enc_celt_buf );
-
-        SKP_Silk_range_enc_init( &psEnc->sCmn.sRC );
         psEnc->sCmn.nBytesInPayloadBuf = 0;
     }
 
@@ -162,8 +156,8 @@ TOC(NSQ)
     /* Encode Parameters                    */
     /****************************************/
 TIC(ENCODE_PARAMS)
-    SKP_Silk_encode_parameters_v4( &psEnc->sCmn, &sEncCtrl.sCmn, &psEnc->sCmn.sRC );
-    FrameTermination_CDF = SKP_Silk_FrameTermination_v4_CDF;
+    SKP_Silk_encode_parameters( &psEnc->sCmn, &sEncCtrl.sCmn, psRangeEnc );
+    FrameTermination_CDF = SKP_Silk_FrameTermination_CDF;
 TOC(ENCODE_PARAMS)
 
     /****************************************/
@@ -178,7 +172,7 @@ TOC(ENCODE_PARAMS)
     psEnc->sCmn.prevLag      = sEncCtrl.sCmn.pitchL[ psEnc->sCmn.nb_subfr - 1 ];
     psEnc->sCmn.first_frame_after_reset = 0;
 
-    if( psEnc->sCmn.sRC.error ) {
+    if( 0 ) { //psEnc->sCmn.sRC.error ) {
         /* Encoder returned error: Clear payload buffer */
         psEnc->sCmn.nFramesInPayloadBuf = 0;
     } else {
@@ -203,21 +197,23 @@ TOC(ENCODE_PARAMS)
         }
 
         /* Add the frame termination info to stream */
-        SKP_Silk_range_encoder( &psEnc->sCmn.sRC, frame_terminator, FrameTermination_CDF );
+        ec_encode_bin( psRangeEnc, FrameTermination_CDF[ frame_terminator ], 
+            FrameTermination_CDF[ frame_terminator + 1 ], 16 );
         for( i = 0; i < psEnc->sCmn.nFramesInPayloadBuf; i++ ) {
-            SKP_Silk_encode_pulses( &psEnc->sCmn.sRC, psEnc->sCmn.sigtype[ i ], psEnc->sCmn.QuantOffsetType[ i ], 
+            SKP_Silk_encode_pulses( psRangeEnc, psEnc->sCmn.sigtype[ i ], psEnc->sCmn.QuantOffsetType[ i ], 
                 &psEnc->sCmn.q[ i * psEnc->sCmn.frame_length ], psEnc->sCmn.frame_length );
         }
 
         /* Payload length so far */
-        SKP_Silk_range_encoder_get_length( &psEnc->sCmn.sRC, &nBytes );
+        nBytes = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
 
         /* Check that there is enough space in external output buffer, and move data */
         if( *pnBytesOut >= nBytes ) {
-            SKP_int bits_in_stream, mask;
-            bits_in_stream = ec_enc_tell( &psEnc->sCmn.sRC.range_enc_celt_state, 0 );
-            ec_enc_done( &psEnc->sCmn.sRC.range_enc_celt_state );
+            //SKP_int bits_in_stream, mask;
+            //bits_in_stream = ec_enc_tell( psRangeEnc, 0 );
+            ec_enc_done( psRangeEnc );
             
+#if 0
             /* Fill up any remaining bits in the last byte with 1s */
             if( bits_in_stream & 7 ) {
                 mask = SKP_RSHIFT( 0xFF, bits_in_stream & 7 );
@@ -226,7 +222,9 @@ TOC(ENCODE_PARAMS)
                 }
             }
             SKP_memcpy( pCode, psEnc->sCmn.sRC.range_enc_celt_state.buf->buf, nBytes * sizeof( SKP_uint8 ) );
+#endif
 
+#if 0
             if( frame_terminator > SKP_SILK_MORE_FRAMES && 
                     *pnBytesOut >= nBytes + psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes ) {
                 /* Get old packet and add to payload. */
@@ -235,8 +233,9 @@ TOC(ENCODE_PARAMS)
                     psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes * sizeof( SKP_uint8 ) );
                 nBytes += psEnc->sCmn.LBRR_buffer[ LBRR_idx ].nBytes;
             }
+#endif
             *pnBytesOut = nBytes;
-        
+
             /* Update FEC buffer */
             SKP_memcpy( psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].payload, LBRRpayload, 
                 nBytesLBRR * sizeof( SKP_uint8 ) );
@@ -245,36 +244,32 @@ TOC(ENCODE_PARAMS)
             psEnc->sCmn.LBRR_buffer[ psEnc->sCmn.oldest_LBRR_idx ].usage = sEncCtrl.sCmn.LBRR_usage;
             psEnc->sCmn.oldest_LBRR_idx = ( ( psEnc->sCmn.oldest_LBRR_idx + 1 ) & LBRR_IDX_MASK );
 
-            /* Reset the number of frames in payload buffer */
-            psEnc->sCmn.nFramesInPayloadBuf = 0;
         } else {
             /* Not enough space: Payload will be discarded */
             *pnBytesOut = 0;
             nBytes      = 0;
-            psEnc->sCmn.nFramesInPayloadBuf = 0;
             ret = SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT;
         }
+
+        /* Reset the number of frames in payload buffer */         
+        psEnc->sCmn.nFramesInPayloadBuf = 0;
     } else {
         /* No payload for you this time */
         *pnBytesOut = 0;
 
         /* Encode that more frames follows */
         frame_terminator = SKP_SILK_MORE_FRAMES;
-        SKP_Silk_range_encoder( &psEnc->sCmn.sRC, frame_terminator, FrameTermination_CDF );
+        ec_encode_bin( psRangeEnc, FrameTermination_CDF[ frame_terminator ], 
+            FrameTermination_CDF[ frame_terminator + 1 ], 16 );
 
         /* Payload length so far */
-        SKP_Silk_range_encoder_get_length( &psEnc->sCmn.sRC, &nBytes );
+        nBytes = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
 
         /* Take into account the q signal that isn't in the bitstream yet */
         nBytes += SKP_Silk_pulses_to_bytes( &psEnc->sCmn, 
             &psEnc->sCmn.q[ psEnc->sCmn.nFramesInPayloadBuf * psEnc->sCmn.frame_length ] );
     }
 
-    /* Check for arithmetic coder errors */
-    if( psEnc->sCmn.sRC.error ) {
-        ret = SKP_SILK_ENC_INTERNAL_ERROR;
-    }
-
     /* simulate number of ms buffered in channel because of exceeding TargetRate */
     psEnc->BufferedInChannel_ms   += ( 8.0f * 1000.0f * ( nBytes - psEnc->sCmn.nBytesInPayloadBuf ) ) / psEnc->sCmn.TargetRate_bps;
     psEnc->BufferedInChannel_ms   -= SUB_FRAME_LENGTH_MS * psEnc->sCmn.nb_subfr;
@@ -314,6 +309,7 @@ TOC(ENCODE_FRAME)
     return( ret );
 }
 
+#if 0  //tmp
 /* Low Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode with lower bitrate           */
 void SKP_Silk_LBRR_encode_FLP(
     SKP_Silk_encoder_state_FLP      *psEnc,             /* I/O  Encoder state FLP                       */
@@ -397,7 +393,7 @@ void SKP_Silk_LBRR_encode_FLP(
         /****************************************/
         /* Encode Parameters                    */
         /****************************************/
-        SKP_Silk_encode_parameters_v4( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sCmn.sRC_LBRR );
+        SKP_Silk_encode_parameters( &psEnc->sCmn, &psEncCtrl->sCmn, &psEnc->sCmn.sRC_LBRR );
         
         /****************************************/
         /* Encode Parameters                    */
@@ -418,7 +414,8 @@ void SKP_Silk_LBRR_encode_FLP(
             frame_terminator = SKP_SILK_LAST_FRAME;
 
             /* Add the frame termination info to stream */
-            SKP_Silk_range_encoder( &psEnc->sCmn.sRC_LBRR, frame_terminator, SKP_Silk_FrameTermination_v4_CDF );
+            ec_encode_bin( psRangeEnc_LBRR, FrameTermination_CDF[ frame_terminator ], 
+                FrameTermination_CDF[ frame_terminator + 1 ], 16 );
 
             /*********************************************/
             /* Encode quantization indices of excitation */
@@ -429,7 +426,7 @@ void SKP_Silk_LBRR_encode_FLP(
             }
 
             /* Payload length so far */
-            SKP_Silk_range_encoder_get_length( &psEnc->sCmn.sRC_LBRR, &nBytes );
+            nBytes = SKP_RSHIFT( ec_enc_tell( psRangeEnc_LBRR, 0 ) + 7, 3 );
 
             /* Check that there is enough space in external output buffer and move data */
             if( *pnBytesOut >= nBytes ) {
@@ -458,7 +455,8 @@ void SKP_Silk_LBRR_encode_FLP(
 
             /* Encode that more frames follows */
             frame_terminator = SKP_SILK_MORE_FRAMES;
-            SKP_Silk_range_encoder( &psEnc->sCmn.sRC_LBRR, frame_terminator, SKP_Silk_FrameTermination_v4_CDF );
+            ec_encode_bin( psRangeEnc_LBRR, FrameTermination_CDF[ frame_terminator ], 
+                FrameTermination_CDF[ frame_terminator + 1 ], 16 );
         }
 
         /* Restore original Gains */
@@ -470,3 +468,4 @@ void SKP_Silk_LBRR_encode_FLP(
         psEnc->sCmn.typeOffsetPrev     = typeOffset;
     }
 }
+#endif
\ No newline at end of file
diff --git a/src_FLP/SKP_Silk_main_FLP.h b/src_FLP/SKP_Silk_main_FLP.h
index 1612e09c88facd8b7fb1537f16296603e69d2317..f06cd7900a2d16c2ed2a221b162d2b4252fa9db7 100644
--- a/src_FLP/SKP_Silk_main_FLP.h
+++ b/src_FLP/SKP_Silk_main_FLP.h
@@ -78,9 +78,9 @@ void SKP_Silk_HP_variable_cutoff_FLP(
 /* Encoder main function */
 SKP_int SKP_Silk_encode_frame_FLP( 
     SKP_Silk_encoder_state_FLP      *psEnc,             /* I/O  Encoder state FLP                       */
-          SKP_uint8                 *pCode,             /* O    Payload                                 */
-          SKP_int16                 *pnBytesOut,        /* I/O  Number of payload bytes;                */
+    SKP_int16                       *pnBytesOut,        /* I/O  Number of payload bytes;                */
                                                         /*      input: max length; output: used         */
+    ec_enc                          *psRangeEnc,        /* I/O  compressor data structure                */
     const SKP_int16                 *pIn                /* I    Input speech frame                      */
 );
 
diff --git a/src_common/SKP_Silk_code_signs.c b/src_common/SKP_Silk_code_signs.c
index aa076ed0ebdfae0a97d585f100fac812e332b609..4bcd82a98997f4acc60411bc4dda960d7c93ba2f 100644
--- a/src_common/SKP_Silk_code_signs.c
+++ b/src_common/SKP_Silk_code_signs.c
@@ -35,34 +35,32 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 /* Encodes signs of excitation */
 void SKP_Silk_encode_signs(
-    SKP_Silk_range_coder_state      *sRC,               /* I/O  Range coder state                       */
-    const SKP_int8                  q[],                /* I    Pulse signal                            */
-    const SKP_int                   length,             /* I    Length of input                         */
-    const SKP_int                   sigtype,            /* I    Signal type                             */
-    const SKP_int                   QuantOffsetType,    /* I    Quantization offset type                */
-    const SKP_int                   RateLevelIndex      /* I    Rate level index                        */
+    ec_enc                      *psRangeEnc,        /* I/O  Compressor data structure                   */
+    const SKP_int8              q[],                /* I    pulse signal                                */
+    const SKP_int               length,             /* I    length of input                             */
+    const SKP_int               sigtype,            /* I    Signal type                                 */
+    const SKP_int               QuantOffsetType,    /* I    Quantization offset type                    */
+    const SKP_int               RateLevelIndex      /* I    Rate Level Index                            */
 )
 {
     SKP_int i;
     SKP_int inData;
-    SKP_uint16 cdf[ 3 ];
+    SKP_uint16 prob;
 
     i = SKP_SMULBB( N_RATE_LEVELS - 1, SKP_LSHIFT( sigtype, 1 ) + QuantOffsetType ) + RateLevelIndex;
-    cdf[ 0 ] = 0;
-    cdf[ 1 ] = SKP_Silk_sign_CDF[ i ];
-    cdf[ 2 ] = 65535;
+    prob = 65536 - SKP_Silk_sign_CDF[ i ];
     
     for( i = 0; i < length; i++ ) {
         if( q[ i ] != 0 ) {
             inData = SKP_enc_map( q[ i ] ); /* - = 0, + = 1 */
-            SKP_Silk_range_encoder( sRC, inData, cdf );
+            ec_enc_bit_prob( psRangeEnc, inData, prob );
         }
     }
 }
 
 /* Decodes signs of excitation */
 void SKP_Silk_decode_signs(
-    SKP_Silk_range_coder_state      *sRC,               /* I/O  Range coder state                           */
+    ec_dec                          *psRangeDec,        /* I/O  Compressor data structure                   */
     SKP_int                         q[],                /* I/O  pulse signal                                */
     const SKP_int                   length,             /* I    length of output                            */
     const SKP_int                   sigtype,            /* I    Signal type                                 */
@@ -81,7 +79,7 @@ void SKP_Silk_decode_signs(
     
     for( i = 0; i < length; i++ ) {
         if( q[ i ] > 0 ) {
-            SKP_Silk_range_decoder( &data, sRC, cdf, 1 );
+            SKP_Silk_range_decoder( &data, psRangeDec, cdf, 1 );
             /* attach sign */
             /* implementation with shift, subtraction, multiplication */
             q[ i ] *= SKP_dec_map( data );
diff --git a/src_common/SKP_Silk_dec_SDK_API.c b/src_common/SKP_Silk_dec_SDK_API.c
index fddce151569881495600baa37ade56410f75d258..9d3a1f7c05fa021e091c6c8ec278895bbd5029a1 100644
--- a/src_common/SKP_Silk_dec_SDK_API.c
+++ b/src_common/SKP_Silk_dec_SDK_API.c
@@ -32,10 +32,10 @@ SKP_int SKP_Silk_SDK_InitDecoder(
 /* Decode a frame */
 SKP_int SKP_Silk_SDK_Decode(
     void*                               decState,       /* I/O: State                                           */
-    SKP_SILK_SDK_DecControlStruct*      decControl,     /* I/O: Control structure                               */
+    SKP_SILK_SDK_DecControlStruct*      decControl,     /* I/O: Control Structure                               */
     SKP_int                             lostFlag,       /* I:   0: no loss, 1 loss                              */
-    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */
-    const SKP_int                       nBytesIn,       /* I:   Number of input Bytes                           */
+    ec_dec                              *psRangeDec,    /* I/O  Compressor data structure                       */
+    const SKP_int                       nBytesIn,       /* I:   Number of input bytes                           */
     SKP_int16                           *samplesOut,    /* O:   Decoded output speech vector                    */
     SKP_int16                           *nSamplesOut    /* I/O: Number of samples (vector/decoded)              */
 )
@@ -65,8 +65,7 @@ SKP_int SKP_Silk_SDK_Decode(
     prev_fs_kHz = psDec->fs_kHz;
     
     /* Call decoder for one frame */
-    ret += SKP_Silk_decode_frame( psDec, samplesOut, nSamplesOut, inData, nBytesIn, 
-            lostFlag, &used_bytes );
+    ret += SKP_Silk_decode_frame( psDec, psRangeDec, samplesOut, nSamplesOut, nBytesIn, lostFlag, &used_bytes );
     
     if( used_bytes ) { /* Only Call if not a packet loss */
         if( psDec->nBytesLeft > 0 && psDec->FrameTermination == SKP_SILK_MORE_FRAMES && psDec->nFramesDecoded < 5 ) {
@@ -132,6 +131,7 @@ SKP_int SKP_Silk_SDK_Decode(
     return ret;
 }
 
+#if 0
 /* Function to find LBRR information in a packet */
 void SKP_Silk_SDK_search_for_LBRR(
     const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */
@@ -155,17 +155,16 @@ void SKP_Silk_SDK_search_for_LBRR(
     sDec.nFramesDecoded = 0;
     sDec.fs_kHz         = 0; /* Force update parameters LPC_order etc */
     SKP_memset( sDec.prevNLSF_Q15, 0, MAX_LPC_ORDER * sizeof( SKP_int ) );
-    SKP_Silk_range_dec_init( &sDec.sRC, inData, ( SKP_int32 )nBytesIn );
 
     /* Decode all parameter indices for the whole packet*/
-    SKP_Silk_decode_indices_v4( &sDec );
+    SKP_Silk_decode_indices( &sDec, psRangeDec );
 
     /* Is there usable LBRR in this packet */
     *nLBRRBytes = 0;
     if( ( sDec.FrameTermination - 1 ) & lost_offset && sDec.FrameTermination > 0 && sDec.nBytesLeft >= 0 ) {
         /* The wanted FEC is present in the packet */
         for( i = 0; i < sDec.nFramesInPacket; i++ ) {
-            SKP_Silk_decode_parameters_v4( &sDec, &sDecCtrl, TempQ, 0 );
+            SKP_Silk_decode_parameters( &sDec, &sDecCtrl, psRangeDec, TempQ, 0 );
             
             if( sDec.nBytesLeft <= 0 || sDec.sRC.error ) {
                 /* Corrupt stream */
@@ -184,10 +183,12 @@ void SKP_Silk_SDK_search_for_LBRR(
         }
     }
 }
+#endif
 
+#if 0  // todo: clean up, make efficient
 /* Getting type of content for a packet */
 void SKP_Silk_SDK_get_TOC(
-    const SKP_uint8                     *inData,        /* I:   Encoded input vector                            */
+    ec_dec                              *psRangeDec,    /* I/O  Compressor data structure                   */
     const SKP_int16                     nBytesIn,       /* I:   Number of input bytes                           */
     SKP_Silk_TOC_struct                 *Silk_TOC       /* O:   Type of content                                 */
 )
@@ -197,10 +198,9 @@ void SKP_Silk_SDK_get_TOC(
 
     sDec.nFramesDecoded = 0;
     sDec.fs_kHz         = 0; /* Force update parameters LPC_order etc */
-    SKP_Silk_range_dec_init( &sDec.sRC, inData, ( SKP_int32 )nBytesIn );
 
     /* Decode all parameter indices for the whole packet*/
-    SKP_Silk_decode_indices_v4( &sDec );
+    SKP_Silk_decode_indices( &sDec );
     
     if( sDec.nFramesInPacket > SILK_MAX_FRAMES_PER_PACKET || sDec.sRC.error ) {
         /* Corrupt packet */
@@ -222,6 +222,7 @@ void SKP_Silk_SDK_get_TOC(
         }
     }
 }
+#endif
 
 /**************************/
 /* Get the version number */
diff --git a/src_common/SKP_Silk_decode_frame.c b/src_common/SKP_Silk_decode_frame.c
index c3a5339e74f5818cade0ecd1fbe311d5836b3c5a..c38a806df4058900b74bddfd824512a0ea3fcdba 100644
--- a/src_common/SKP_Silk_decode_frame.c
+++ b/src_common/SKP_Silk_decode_frame.c
@@ -33,19 +33,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 /* Decode frame */
 /****************/
 SKP_int SKP_Silk_decode_frame(
-    SKP_Silk_decoder_state          *psDec,             /* I/O  Pointer to Silk decoder state               */
-    SKP_int16                       pOut[],             /* O    Pointer to output speech frame              */
-    SKP_int16                       *pN,                /* O    Pointer to size of output frame             */
-    const SKP_uint8                 pCode[],            /* I    Pointer to payload                          */
-    const SKP_int                   nBytes,             /* I    Payload length                              */
-    SKP_int                         action,             /* I    Action from Jitter Buffer                   */
-    SKP_int                         *decBytes           /* O    Used bytes to decode this frame             */
+    SKP_Silk_decoder_state      *psDec,             /* I/O  Pointer to Silk decoder state               */
+    ec_dec                      *psRangeDec,        /* I/O  Compressor data structure                   */
+    SKP_int16                   pOut[],             /* O    Pointer to output speech frame              */
+    SKP_int16                   *pN,                /* O    Pointer to size of output frame             */
+    const SKP_int               nBytes,             /* I    Payload length                              */
+    SKP_int                     action,             /* I    Action from Jitter Buffer                   */
+    SKP_int                     *decBytes           /* O    Used bytes to decode this frame             */
 )
 {
     SKP_Silk_decoder_control sDecCtrl;
     SKP_int         L, fs_Khz_old, nb_subfr_old, mv_len, ret = 0;
     SKP_int         Pulses[ MAX_FRAME_LENGTH ];
-    ec_byte_buffer range_dec_celt_buf;
 
 TIC(decode_frame)
 
@@ -66,41 +65,33 @@ TIC(decode_frame)
         fs_Khz_old    = psDec->fs_kHz;
         nb_subfr_old  = psDec->nb_subfr;
         if( psDec->nFramesDecoded == 0 ) {
-            /* Initialize range decoder state */
-            /* check input */
-            psDec->sRC.error = 0;
-            if( nBytes > MAX_ARITHM_BYTES ) {
-                psDec->sRC.error = RANGE_CODER_DEC_PAYLOAD_TOO_LONG;
-            }
-            ec_byte_writeinit_buffer( &range_dec_celt_buf, psDec->sRC.buffer, nBytes );
-            SKP_memcpy( psDec->sRC.buffer, pCode, nBytes * sizeof( SKP_uint8 ) );
-            ec_dec_init( &psDec->sRC.range_dec_celt_state, &range_dec_celt_buf );
-
-            SKP_Silk_decode_indices_v4( psDec );
+            SKP_Silk_decode_indices( psDec, psRangeDec );
         }
 
         /********************************************/
         /* Decode parameters and pulse signal       */
         /********************************************/
 TIC(decode_params)
-        SKP_Silk_decode_parameters_v4( psDec, &sDecCtrl, Pulses, 1 );
+        SKP_Silk_decode_parameters( psDec, &sDecCtrl, psRangeDec, Pulses, 1 );
 TOC(decode_params)
 
-        if( psDec->sRC.error ) {
+        if( 0 ) { //psDec->sRC.error ) {
             psDec->nBytesLeft = 0;
 
             action              = 1; /* PLC operation */
             SKP_Silk_decoder_set_fs( psDec, fs_Khz_old, nb_subfr_old );
 
             /* Avoid crashing */
-            *decBytes = psDec->sRC.range_dec_celt_state.buf->storage; 
+            *decBytes = psRangeDec->buf->storage; 
+            /*
             if( psDec->sRC.error == RANGE_CODER_DEC_PAYLOAD_TOO_LONG ) {
                 ret = SKP_SILK_DEC_PAYLOAD_TOO_LARGE;
             } else {
                 ret = SKP_SILK_DEC_PAYLOAD_ERROR;
             }
+            */
         } else {
-            *decBytes = psDec->sRC.range_dec_celt_state.buf->storage - psDec->nBytesLeft;
+            *decBytes = psRangeDec->buf->storage - psDec->nBytesLeft;
             psDec->nFramesDecoded++;
         
             /* Update lengths. Sampling frequency could have changed */
diff --git a/src_common/SKP_Silk_decode_indices_v4.c b/src_common/SKP_Silk_decode_indices.c
similarity index 72%
rename from src_common/SKP_Silk_decode_indices_v4.c
rename to src_common/SKP_Silk_decode_indices.c
index e41797ba4e35f1533140a5952ca20fb381d314cf..3ba8a77cbc066ebb9da8f90c9fd869da79a2f55b 100644
--- a/src_common/SKP_Silk_decode_indices_v4.c
+++ b/src_common/SKP_Silk_decode_indices.c
@@ -28,31 +28,26 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "SKP_Silk_main.h"
 
 /* Decode indices from payload */
-void SKP_Silk_decode_indices_v4(
-    SKP_Silk_decoder_state      *psDec            /* I/O    State                              */
+void SKP_Silk_decode_indices(
+    SKP_Silk_decoder_state      *psDec,             /* I/O  State                                       */
+    ec_dec                      *psRangeDec         /* I/O  Compressor data structure                   */
 )
 {
     SKP_int   i, k, Ix, fs_kHz_dec, nb_subfr, FrameIndex = 0, FrameTermination;
     SKP_int   sigtype, QuantOffsetType, seed_int, nBytesUsed;
     SKP_int   decode_absolute_lagIndex, delta_lagIndex, prev_lagIndex = 0;
     const SKP_Silk_NLSF_CB_struct *psNLSF_CB = NULL;
-    SKP_Silk_range_coder_state  *psRC = &psDec->sRC;
+
     /************************/
     /* Decode sampling rate */
     /************************/
     /* only done for first frame of packet */
     if( psDec->nFramesDecoded == 0 ) {
-        SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_SamplingRates_CDF, SKP_Silk_SamplingRates_offset );
-
-        /* check that sampling rate is supported */
-        if( Ix < 0 || Ix > 3 ) {
-            psRC->error = RANGE_CODER_ILLEGAL_SAMPLING_RATE;
-            return;
-        }
+        SKP_Silk_range_decoder( &Ix, psRangeDec, SKP_Silk_SamplingRates_CDF, SKP_Silk_SamplingRates_offset );
         fs_kHz_dec = SKP_Silk_SamplingRates_table[ Ix ];
 
         /* Convert number of subframes to index */
-        SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_NbSubframes_CDF, SKP_Silk_NbSubframes_offset );
+        SKP_Silk_range_decoder( &Ix, psRangeDec, SKP_Silk_NbSubframes_CDF, SKP_Silk_NbSubframes_offset );
         nb_subfr = (Ix + 1) << 1;
         SKP_assert( nb_subfr == MAX_NB_SUBFR >> 1 || nb_subfr == MAX_NB_SUBFR );
         
@@ -66,17 +61,17 @@ void SKP_Silk_decode_indices_v4(
         /*******************/
         /* Decode VAD flag */
         /*******************/
-        SKP_Silk_range_decoder( &psDec->vadFlagBuf[ FrameIndex ], psRC, SKP_Silk_vadflag_CDF, SKP_Silk_vadflag_offset );
+        SKP_Silk_range_decoder( &psDec->vadFlagBuf[ FrameIndex ], psRangeDec, SKP_Silk_vadflag_CDF, SKP_Silk_vadflag_offset );
 
         /*******************************************/
         /* Decode signal type and quantizer offset */
         /*******************************************/
         if( FrameIndex == 0 ) {
             /* first frame in packet: independent coding */
-            SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_type_offset_CDF, SKP_Silk_type_offset_CDF_offset );
+            SKP_Silk_range_decoder( &Ix, psRangeDec, SKP_Silk_type_offset_CDF, SKP_Silk_type_offset_CDF_offset );
         } else {
             /* condidtional coding */
-            SKP_Silk_range_decoder( &Ix, psRC, SKP_Silk_type_offset_joint_CDF[ psDec->typeOffsetPrev ], 
+            SKP_Silk_range_decoder( &Ix, psRangeDec, SKP_Silk_type_offset_joint_CDF[ psDec->typeOffsetPrev ], 
                     SKP_Silk_type_offset_CDF_offset );
         }
         sigtype               = SKP_RSHIFT( Ix, 1 );
@@ -89,15 +84,15 @@ void SKP_Silk_decode_indices_v4(
         /* first subframe */    
         if( FrameIndex == 0 ) {
             /* first frame in packet: independent coding */
-            SKP_Silk_range_decoder( &psDec->GainsIndices[ FrameIndex ][ 0 ], psRC, SKP_Silk_gain_CDF[ sigtype ], SKP_Silk_gain_CDF_offset );
+            SKP_Silk_range_decoder( &psDec->GainsIndices[ FrameIndex ][ 0 ], psRangeDec, SKP_Silk_gain_CDF[ sigtype ], SKP_Silk_gain_CDF_offset );
         } else {
             /* condidtional coding */
-            SKP_Silk_range_decoder( &psDec->GainsIndices[ FrameIndex ][ 0 ], psRC, SKP_Silk_delta_gain_CDF, SKP_Silk_delta_gain_CDF_offset );
+            SKP_Silk_range_decoder( &psDec->GainsIndices[ FrameIndex ][ 0 ], psRangeDec, SKP_Silk_delta_gain_CDF, SKP_Silk_delta_gain_CDF_offset );
         }
 
         /* remaining subframes */
         for( i = 1; i < psDec->nb_subfr; i++ ) {
-            SKP_Silk_range_decoder( &psDec->GainsIndices[ FrameIndex ][ i ], psRC, SKP_Silk_delta_gain_CDF, SKP_Silk_delta_gain_CDF_offset );
+            SKP_Silk_range_decoder( &psDec->GainsIndices[ FrameIndex ][ i ], psRangeDec, SKP_Silk_delta_gain_CDF, SKP_Silk_delta_gain_CDF_offset );
         }
         
         /**********************/
@@ -108,12 +103,14 @@ void SKP_Silk_decode_indices_v4(
         psNLSF_CB = psDec->psNLSF_CB[ sigtype ];
 
         /* Arithmetically decode NLSF path */
-        SKP_Silk_range_decoder_multi( psDec->NLSFIndices[ FrameIndex ], psRC, psNLSF_CB->StartPtr, psNLSF_CB->MiddleIx, psNLSF_CB->nStages );
+        for( i = 0; i < psNLSF_CB->nStages; i++ ) {
+            SKP_Silk_range_decoder( &psDec->NLSFIndices[ FrameIndex ][ i ], psRangeDec, psNLSF_CB->StartPtr[ i ], psNLSF_CB->MiddleIx[ i ] );
+        }
         
         /***********************************/
         /* Decode LSF interpolation factor */
         /***********************************/
-        SKP_Silk_range_decoder( &psDec->NLSFInterpCoef_Q2[ FrameIndex ], psRC, SKP_Silk_NLSF_interpolation_factor_CDF, 
+        SKP_Silk_range_decoder( &psDec->NLSFInterpCoef_Q2[ FrameIndex ], psRangeDec, SKP_Silk_NLSF_interpolation_factor_CDF, 
             SKP_Silk_NLSF_interpolation_factor_offset );
         
         if( sigtype == SIG_TYPE_VOICED ) {
@@ -124,7 +121,7 @@ void SKP_Silk_decode_indices_v4(
             decode_absolute_lagIndex = 1;
             if( FrameIndex > 0 && psDec->sigtype[ FrameIndex - 1 ] == SIG_TYPE_VOICED ) {
                 /* Decode Delta index */
-                SKP_Silk_range_decoder( &delta_lagIndex,psRC, SKP_Silk_pitch_delta_CDF,  SKP_Silk_pitch_delta_CDF_offset );
+                SKP_Silk_range_decoder( &delta_lagIndex, psRangeDec, SKP_Silk_pitch_delta_CDF,  SKP_Silk_pitch_delta_CDF_offset );
                 if( delta_lagIndex < ( MAX_DELTA_LAG << 1 ) + 1 ) {
                     delta_lagIndex = delta_lagIndex - MAX_DELTA_LAG;
                     psDec->lagIndex[ FrameIndex ] = prev_lagIndex + delta_lagIndex;
@@ -134,13 +131,13 @@ void SKP_Silk_decode_indices_v4(
             if( decode_absolute_lagIndex ) {
                 /* Absolute decoding */
                 if( psDec->fs_kHz == 8 ) {
-                    SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRC, SKP_Silk_pitch_lag_NB_CDF,  SKP_Silk_pitch_lag_NB_CDF_offset );
+                    SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRangeDec, SKP_Silk_pitch_lag_NB_CDF,  SKP_Silk_pitch_lag_NB_CDF_offset );
                 } else if( psDec->fs_kHz == 12 ) {
-                    SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRC, SKP_Silk_pitch_lag_MB_CDF,  SKP_Silk_pitch_lag_MB_CDF_offset );
+                    SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRangeDec, SKP_Silk_pitch_lag_MB_CDF,  SKP_Silk_pitch_lag_MB_CDF_offset );
                 } else if( psDec->fs_kHz == 16 ) {
-                    SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRC, SKP_Silk_pitch_lag_WB_CDF,  SKP_Silk_pitch_lag_WB_CDF_offset );
+                    SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRangeDec, SKP_Silk_pitch_lag_WB_CDF,  SKP_Silk_pitch_lag_WB_CDF_offset );
                 } else {
-                    SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRC, SKP_Silk_pitch_lag_SWB_CDF, SKP_Silk_pitch_lag_SWB_CDF_offset );
+                    SKP_Silk_range_decoder( &psDec->lagIndex[ FrameIndex ], psRangeDec, SKP_Silk_pitch_lag_SWB_CDF, SKP_Silk_pitch_lag_SWB_CDF_offset );
                 }
             }
             prev_lagIndex = psDec->lagIndex[ FrameIndex ];
@@ -148,38 +145,38 @@ void SKP_Silk_decode_indices_v4(
             /* Get countour index */
             if( psDec->fs_kHz == 8 ) {
                 /* Less codevectors used in 8 khz mode */
-                SKP_Silk_range_decoder( &psDec->contourIndex[ FrameIndex ], psRC, SKP_Silk_pitch_contour_NB_CDF, SKP_Silk_pitch_contour_NB_CDF_offset );
+                SKP_Silk_range_decoder( &psDec->contourIndex[ FrameIndex ], psRangeDec, SKP_Silk_pitch_contour_NB_CDF, SKP_Silk_pitch_contour_NB_CDF_offset );
             } else {
                 /* Joint for 12, 16, and 24 khz */
-                SKP_Silk_range_decoder( &psDec->contourIndex[ FrameIndex ], psRC, SKP_Silk_pitch_contour_CDF, SKP_Silk_pitch_contour_CDF_offset );
+                SKP_Silk_range_decoder( &psDec->contourIndex[ FrameIndex ], psRangeDec, SKP_Silk_pitch_contour_CDF, SKP_Silk_pitch_contour_CDF_offset );
             }
             
             /********************/
             /* Decode LTP gains */
             /********************/
             /* Decode PERIndex value */
-            SKP_Silk_range_decoder( &psDec->PERIndex[ FrameIndex ], psRC, SKP_Silk_LTP_per_index_CDF, SKP_Silk_LTP_per_index_CDF_offset );
+            SKP_Silk_range_decoder( &psDec->PERIndex[ FrameIndex ], psRangeDec, SKP_Silk_LTP_per_index_CDF, SKP_Silk_LTP_per_index_CDF_offset );
             
             for( k = 0; k < psDec->nb_subfr; k++ ) {
-                SKP_Silk_range_decoder( &psDec->LTPIndex[ FrameIndex ][ k ], psRC, SKP_Silk_LTP_gain_CDF_ptrs[ psDec->PERIndex[ FrameIndex ] ], 
+                SKP_Silk_range_decoder( &psDec->LTPIndex[ FrameIndex ][ k ], psRangeDec, SKP_Silk_LTP_gain_CDF_ptrs[ psDec->PERIndex[ FrameIndex ] ], 
                     SKP_Silk_LTP_gain_CDF_offsets[ psDec->PERIndex[ FrameIndex ] ] );
             }
 
             /**********************/
             /* Decode LTP scaling */
             /**********************/
-            SKP_Silk_range_decoder( &psDec->LTP_scaleIndex[ FrameIndex ], psRC, SKP_Silk_LTPscale_CDF, SKP_Silk_LTPscale_offset );
+            SKP_Silk_range_decoder( &psDec->LTP_scaleIndex[ FrameIndex ], psRangeDec, SKP_Silk_LTPscale_CDF, SKP_Silk_LTPscale_offset );
         }
 
         /***************/
         /* Decode seed */
         /***************/
-        SKP_Silk_range_decoder( &seed_int, psRC, SKP_Silk_Seed_CDF, SKP_Silk_Seed_offset );
+        SKP_Silk_range_decoder( &seed_int, psRangeDec, SKP_Silk_Seed_CDF, SKP_Silk_Seed_offset );
         psDec->Seed[ FrameIndex ] = ( SKP_int32 )seed_int;
         /**************************************/
         /* Decode Frame termination indicator */
         /**************************************/
-        SKP_Silk_range_decoder( &FrameTermination, psRC, SKP_Silk_FrameTermination_v4_CDF, SKP_Silk_FrameTermination_v4_offset );
+        SKP_Silk_range_decoder( &FrameTermination, psRangeDec, SKP_Silk_FrameTermination_CDF, SKP_Silk_FrameTermination_offset );
 
         psDec->sigtype[ FrameIndex ]         = sigtype;
         psDec->QuantOffsetType[ FrameIndex ] = QuantOffsetType;
@@ -190,12 +187,8 @@ void SKP_Silk_decode_indices_v4(
     /****************************************/
     /* get number of bytes used so far      */
     /****************************************/
-    SKP_Silk_range_decoder_get_length( psRC, &nBytesUsed );
-    psDec->nBytesLeft = psRC->range_dec_celt_state.buf->storage - nBytesUsed;
-
-    if( psDec->nBytesLeft < 0 ) {
-        psRC->error = RANGE_CODER_READ_BEYOND_BUFFER;
-    }
+    nBytesUsed = SKP_RSHIFT( ec_dec_tell( psRangeDec, 0 ) + 7, 3 );
+    psDec->nBytesLeft = psRangeDec->buf->storage - nBytesUsed;
 
     psDec->nFramesInPacket  = FrameIndex;
     psDec->FrameTermination = FrameTermination;
diff --git a/src_common/SKP_Silk_decode_parameters_v4.c b/src_common/SKP_Silk_decode_parameters.c
similarity index 90%
rename from src_common/SKP_Silk_decode_parameters_v4.c
rename to src_common/SKP_Silk_decode_parameters.c
index 67027422daf094cdcf78bc34df2dea8ea997868f..eb9077bcce66ba9ed79a4e09ea92a2cca8db2cd1 100644
--- a/src_common/SKP_Silk_decode_parameters_v4.c
+++ b/src_common/SKP_Silk_decode_parameters.c
@@ -28,9 +28,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "SKP_Silk_main.h"
 
 /* Decode parameters from payload */
-void SKP_Silk_decode_parameters_v4(
+void SKP_Silk_decode_parameters(
     SKP_Silk_decoder_state      *psDec,                                 /* I/O  State                                    */
     SKP_Silk_decoder_control    *psDecCtrl,                             /* I/O  Decoder control                          */
+    ec_dec                      *psRangeDec,                            /* I/O  Compressor data structure                */
     SKP_int                     q[ MAX_FRAME_LENGTH ],                  /* O    Excitation signal                        */
     const SKP_int               fullDecoding                            /* I    Flag to tell if only arithmetic decoding */
 )
@@ -39,7 +40,6 @@ void SKP_Silk_decode_parameters_v4(
     SKP_int   pNLSF_Q15[ MAX_LPC_ORDER ], pNLSF0_Q15[ MAX_LPC_ORDER ];
     const SKP_int16 *cbk_ptr_Q14;
     const SKP_Silk_NLSF_CB_struct *psNLSF_CB = NULL;
-    SKP_Silk_range_coder_state  *psRC = &psDec->sRC;
     
     psDec->FrameTermination       = SKP_SILK_MORE_FRAMES;
     psDecCtrl->sigtype            = psDec->sigtype[ psDec->nFramesDecoded ];
@@ -135,25 +135,14 @@ void SKP_Silk_decode_parameters_v4(
     /* Decode quantization indices of excitation */
     /*********************************************/
 TIC(decode_pulses)
-    SKP_Silk_decode_pulses( psRC, psDecCtrl, q, psDec->frame_length );
+    SKP_Silk_decode_pulses( psRangeDec, psDecCtrl, q, psDec->frame_length );
 TOC(decode_pulses)
 
     /****************************************/
     /* get number of bytes used so far      */
     /****************************************/
-    SKP_Silk_range_decoder_get_length( psRC, &nBytesUsed );
-    psDec->nBytesLeft = psRC->range_dec_celt_state.buf->storage - nBytesUsed;
-
-    if( psDec->nBytesLeft < 0 ) {
-        psRC->error = RANGE_CODER_READ_BEYOND_BUFFER;
-    }
-
-    /****************************************/
-    /* check remaining bits in last byte    */
-    /****************************************/
-    if( psDec->nBytesLeft == 0 ) {
-        SKP_Silk_range_coder_check_after_decoding( psRC );
-    }
+    nBytesUsed = SKP_RSHIFT( ec_dec_tell( psRangeDec, 0 ) + 7, 3 );
+    psDec->nBytesLeft = psRangeDec->buf->storage - nBytesUsed;
 
     if( psDec->nFramesInPacket == (psDec->nFramesDecoded + 1)) {
         /* To indicate the packet has been fully decoded */
diff --git a/src_common/SKP_Silk_decode_pulses.c b/src_common/SKP_Silk_decode_pulses.c
index bdcd37c56302ff7659541a2ebda190edc48b3813..503757aa759c7c64b49ec49d3c9568848350408b 100644
--- a/src_common/SKP_Silk_decode_pulses.c
+++ b/src_common/SKP_Silk_decode_pulses.c
@@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 /* Decode quantization indices of excitation */
 /*********************************************/
 void SKP_Silk_decode_pulses(
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  Range coder state                           */
+    ec_dec                          *psRangeDec,        /* I/O  Compressor data structure                   */
     SKP_Silk_decoder_control        *psDecCtrl,         /* I/O  Decoder control                             */
     SKP_int                         q[],                /* O    Excitation signal                           */
     const SKP_int                   frame_length        /* I    Frame length (preliminary)                  */
@@ -45,7 +45,7 @@ void SKP_Silk_decode_pulses(
     /*********************/
     /* Decode rate level */
     /*********************/
-    SKP_Silk_range_decoder( &psDecCtrl->RateLevelIndex, psRC, 
+    SKP_Silk_range_decoder( &psDecCtrl->RateLevelIndex, psRangeDec, 
             SKP_Silk_rate_levels_CDF[ psDecCtrl->sigtype ], SKP_Silk_rate_levels_CDF_offset );
 
     /* Calculate number of shell blocks */
@@ -61,12 +61,12 @@ void SKP_Silk_decode_pulses(
     cdf_ptr = SKP_Silk_pulses_per_block_CDF[ psDecCtrl->RateLevelIndex ];
     for( i = 0; i < iter; i++ ) {
         nLshifts[ i ] = 0;
-        SKP_Silk_range_decoder( &sum_pulses[ i ], psRC, cdf_ptr, SKP_Silk_pulses_per_block_CDF_offset );
+        SKP_Silk_range_decoder( &sum_pulses[ i ], psRangeDec, cdf_ptr, SKP_Silk_pulses_per_block_CDF_offset );
 
         /* LSB indication */
         while( sum_pulses[ i ] == ( MAX_PULSES + 1 ) ) {
             nLshifts[ i ]++;
-            SKP_Silk_range_decoder( &sum_pulses[ i ], psRC, 
+            SKP_Silk_range_decoder( &sum_pulses[ i ], psRangeDec, 
                     SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ], SKP_Silk_pulses_per_block_CDF_offset );
         }
     }
@@ -76,7 +76,7 @@ void SKP_Silk_decode_pulses(
     /***************************************************/
     for( i = 0; i < iter; i++ ) {
         if( sum_pulses[ i ] > 0 ) {
-            SKP_Silk_shell_decoder( &q[ SKP_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], psRC, sum_pulses[ i ] );
+            SKP_Silk_shell_decoder( &q[ SKP_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], psRangeDec, sum_pulses[ i ] );
         } else {
             SKP_memset( &q[ SKP_SMULBB( i, SHELL_CODEC_FRAME_LENGTH ) ], 0, SHELL_CODEC_FRAME_LENGTH * sizeof( SKP_int ) );
         }
@@ -93,7 +93,7 @@ void SKP_Silk_decode_pulses(
                 abs_q = pulses_ptr[ k ];
                 for( j = 0; j < nLS; j++ ) {
                     abs_q = SKP_LSHIFT( abs_q, 1 ); 
-                    SKP_Silk_range_decoder( &bit, psRC, SKP_Silk_lsb_CDF, 1 );
+                    SKP_Silk_range_decoder( &bit, psRangeDec, SKP_Silk_lsb_CDF, 1 );
                     abs_q += bit;
                 }
                 pulses_ptr[ k ] = abs_q;
@@ -104,6 +104,6 @@ void SKP_Silk_decode_pulses(
     /****************************************/
     /* Decode and add signs to pulse signal */
     /****************************************/
-    SKP_Silk_decode_signs( psRC, q, frame_length, psDecCtrl->sigtype, 
+    SKP_Silk_decode_signs( psRangeDec, q, frame_length, psDecCtrl->sigtype, 
         psDecCtrl->QuantOffsetType, psDecCtrl->RateLevelIndex);
 }
diff --git a/src_common/SKP_Silk_enc_API.c b/src_common/SKP_Silk_enc_API.c
index 79265273c992f7d1f6c079649c2c8eb537109010..fa740591bab5ad60077214c404eaf592aa1424f8 100644
--- a/src_common/SKP_Silk_enc_API.c
+++ b/src_common/SKP_Silk_enc_API.c
@@ -121,8 +121,8 @@ SKP_int SKP_Silk_SDK_Encode(
     const SKP_Silk_EncodeControlStruct  *encControl,    /* I:   Control structure                               */
     const SKP_int16                     *samplesIn,     /* I:   Speech sample input vector                      */
     SKP_int                             nSamplesIn,     /* I:   Number of samples in input vector               */
-    SKP_uint8                           *outData,       /* O:   Encoded output vector                           */
-    SKP_int16                           *nBytesOut      /* I/O: Number of bytes in outData (input: Max bytes)   */
+    ec_enc                              *psRangeEnc,    /* I/O  Compressor data structure                       */
+    SKP_int16                           *nBytesOut      /* I/O: Number of bytes in payload (input: Max bytes)   */
 )
 {
     SKP_int   max_internal_fs_kHz, PacketSize_ms, PacketLoss_perc, UseInBandFEC, UseDTX, ret = SKP_SILK_NO_ERROR;
@@ -214,12 +214,12 @@ SKP_int SKP_Silk_SDK_Encode(
             if( MaxBytesOut == 0 ) {
                 /* No payload obtained so far */
                 MaxBytesOut = *nBytesOut;
-                if( ( ret = SKP_Silk_encode_frame_Fxx( psEnc, outData, &MaxBytesOut, psEnc->sCmn.inputBuf ) ) != 0 ) {
+                if( ( ret = SKP_Silk_encode_frame_Fxx( psEnc, &MaxBytesOut, psRangeEnc, psEnc->sCmn.inputBuf ) ) != 0 ) {
                     SKP_assert( 0 );
                 }
             } else {
-                /* outData already contains a payload */
-                if( ( ret = SKP_Silk_encode_frame_Fxx( psEnc, outData, nBytesOut, psEnc->sCmn.inputBuf ) ) != 0 ) {
+                /* Already contains a payload */
+                if( ( ret = SKP_Silk_encode_frame_Fxx( psEnc, nBytesOut, psRangeEnc, psEnc->sCmn.inputBuf ) ) != 0 ) {
                     SKP_assert( 0 );
                 }
                 /* Check that no second payload was created */
diff --git a/src_common/SKP_Silk_encode_parameters_v4.c b/src_common/SKP_Silk_encode_parameters.c
similarity index 59%
rename from src_common/SKP_Silk_encode_parameters_v4.c
rename to src_common/SKP_Silk_encode_parameters.c
index 07c6e047ce8fd28603986726ee7b666633569413..dd66154c3f01f95cd322f7bd86a9bc9217bb8844 100644
--- a/src_common/SKP_Silk_encode_parameters_v4.c
+++ b/src_common/SKP_Silk_encode_parameters.c
@@ -30,10 +30,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 /*******************************************/
 /* Encode parameters to create the payload */
 /*******************************************/
-void SKP_Silk_encode_parameters_v4(
-    SKP_Silk_encoder_state          *psEncC,        /* I/O  Encoder state                   */
-    SKP_Silk_encoder_control        *psEncCtrlC,    /* I/O  Encoder control                 */
-    SKP_Silk_range_coder_state      *psRC           /* I/O  Range encoder state             */
+void SKP_Silk_encode_parameters(
+    SKP_Silk_encoder_state      *psEncC,            /* I/O  Encoder state                               */
+    SKP_Silk_encoder_control    *psEncCtrlC,        /* I/O  Encoder control                             */
+    ec_enc                      *psRangeEnc         /* I/O  Compressor data structure                   */
 )
 {
     SKP_int   i, k, typeOffset;
@@ -57,18 +57,18 @@ void SKP_Silk_encode_parameters_v4(
                 break;
             }
         }
-        SKP_Silk_range_encoder( psRC, i, SKP_Silk_SamplingRates_CDF );
+        ec_encode_bin( psRangeEnc, SKP_Silk_SamplingRates_CDF[ i ], SKP_Silk_SamplingRates_CDF[ i + 1 ], 16 );
 
         /* Convert number of subframes to index */
         SKP_assert( psEncC->nb_subfr == MAX_NB_SUBFR >> 1 || psEncC->nb_subfr == MAX_NB_SUBFR );
         i = (psEncC->nb_subfr >> 1) - 1;
-        SKP_Silk_range_encoder( psRC, i, SKP_Silk_NbSubframes_CDF );
+        ec_enc_bit_prob( psRangeEnc, i, 65536 - SKP_Silk_NbSubframes_CDF[ 1 ] );
     }
 
     /*********************************************/
     /* Encode VAD flag                           */
     /*********************************************/
-    SKP_Silk_range_encoder( psRC, psEncC->vadFlag, SKP_Silk_vadflag_CDF );
+    ec_enc_bit_prob( psRangeEnc, psEncC->vadFlag, 65536 - SKP_Silk_vadflag_CDF[ 1 ] );
 
     /*******************************************/
     /* Encode signal type and quantizer offset */
@@ -76,10 +76,12 @@ void SKP_Silk_encode_parameters_v4(
     typeOffset = 2 * psEncCtrlC->sigtype + psEncCtrlC->QuantOffsetType;
     if( psEncC->nFramesInPayloadBuf == 0 ) {
         /* first frame in packet: independent coding */
-        SKP_Silk_range_encoder( psRC, typeOffset, SKP_Silk_type_offset_CDF );
+        ec_encode_bin( psRangeEnc, SKP_Silk_type_offset_CDF[ typeOffset ], 
+            SKP_Silk_type_offset_CDF[ typeOffset + 1 ], 16 );
     } else {
         /* condidtional coding */
-        SKP_Silk_range_encoder( psRC, typeOffset, SKP_Silk_type_offset_joint_CDF[ psEncC->typeOffsetPrev ] );
+        ec_encode_bin( psRangeEnc, SKP_Silk_type_offset_joint_CDF[ psEncC->typeOffsetPrev ][ typeOffset ], 
+            SKP_Silk_type_offset_joint_CDF[ psEncC->typeOffsetPrev ][ typeOffset + 1 ], 16 );
     }
     psEncC->typeOffsetPrev = typeOffset;
 
@@ -87,24 +89,27 @@ void SKP_Silk_encode_parameters_v4(
     /* Encode gains */
     /****************/
 #ifdef SAVE_ALL_INTERNAL_DATA
-    SKP_Silk_range_encoder_get_length( psRC, &nBytes_before );
+    nBytes_before = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
 #endif
     /* first subframe */
     if( psEncC->nFramesInPayloadBuf == 0 ) {
         /* first frame in packet: independent coding */
-        SKP_Silk_range_encoder( psRC, psEncCtrlC->GainsIndices[ 0 ], SKP_Silk_gain_CDF[ psEncCtrlC->sigtype ] );
+        ec_encode_bin( psRangeEnc, SKP_Silk_gain_CDF[ psEncCtrlC->sigtype ][ psEncCtrlC->GainsIndices[ 0 ] ], 
+            SKP_Silk_gain_CDF[ psEncCtrlC->sigtype ][ psEncCtrlC->GainsIndices[ 0 ] + 1 ], 16 );
     } else {
         /* condidtional coding */
-        SKP_Silk_range_encoder( psRC, psEncCtrlC->GainsIndices[ 0 ], SKP_Silk_delta_gain_CDF );
+        ec_encode_bin( psRangeEnc, SKP_Silk_delta_gain_CDF[ psEncCtrlC->GainsIndices[ 0 ] ], 
+            SKP_Silk_delta_gain_CDF[ psEncCtrlC->GainsIndices[ 0 ] + 1 ], 16 );
     }
 
     /* remaining subframes */
     for( i = 1; i < psEncC->nb_subfr; i++ ) {
-        SKP_Silk_range_encoder( psRC, psEncCtrlC->GainsIndices[ i ], SKP_Silk_delta_gain_CDF );
+        ec_encode_bin( psRangeEnc, SKP_Silk_delta_gain_CDF[ psEncCtrlC->GainsIndices[ i ] ], 
+            SKP_Silk_delta_gain_CDF[ psEncCtrlC->GainsIndices[ i ] + 1 ], 16 );
     }
 
 #ifdef SAVE_ALL_INTERNAL_DATA
-    SKP_Silk_range_encoder_get_length( psRC, &nBytes_after );
+    nBytes_after = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
     nBytes_after -= nBytes_before; // bytes just added
     DEBUG_STORE_DATA( nBytes_gains.dat, &nBytes_after, sizeof( SKP_int ) );
 #endif
@@ -113,18 +118,22 @@ void SKP_Silk_encode_parameters_v4(
     /* Encode NLSFs */
     /****************/
 #ifdef SAVE_ALL_INTERNAL_DATA
-    SKP_Silk_range_encoder_get_length( psRC, &nBytes_before );
+    nBytes_before = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
 #endif
     /* Range encoding of the NLSF path */
     psNLSF_CB = psEncC->psNLSF_CB[ psEncCtrlC->sigtype ];
-    SKP_Silk_range_encoder_multi( psRC, psEncCtrlC->NLSFIndices, psNLSF_CB->StartPtr, psNLSF_CB->nStages );
+    for( i = 0; i < psNLSF_CB->nStages; i++ ) {
+        ec_encode_bin( psRangeEnc, psNLSF_CB->StartPtr[ i ][ psEncCtrlC->NLSFIndices[ i ] ], 
+            psNLSF_CB->StartPtr[ i ][ psEncCtrlC->NLSFIndices[ i ] + 1 ], 16 );
+    }
 
     /* Encode NLSF interpolation factor */
     SKP_assert( psEncC->useInterpolatedNLSFs == 1 || psEncCtrlC->NLSFInterpCoef_Q2 == ( 1 << 2 ) );
-    SKP_Silk_range_encoder( psRC, psEncCtrlC->NLSFInterpCoef_Q2, SKP_Silk_NLSF_interpolation_factor_CDF );
+    ec_encode_bin( psRangeEnc, SKP_Silk_NLSF_interpolation_factor_CDF[ psEncCtrlC->NLSFInterpCoef_Q2 ], 
+        SKP_Silk_NLSF_interpolation_factor_CDF[ psEncCtrlC->NLSFInterpCoef_Q2 + 1 ], 16 );
 
 #ifdef SAVE_ALL_INTERNAL_DATA
-    SKP_Silk_range_encoder_get_length( psRC, &nBytes_after );
+    nBytes_after = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
     nBytes_after -= nBytes_before; // bytes just added
     DEBUG_STORE_DATA( nBytes_LSF.dat, &nBytes_after, sizeof( SKP_int ) );
 #endif
@@ -134,7 +143,7 @@ void SKP_Silk_encode_parameters_v4(
         /* Encode pitch lags */
         /*********************/
 #ifdef SAVE_ALL_INTERNAL_DATA
-        SKP_Silk_range_encoder_get_length( psRC, &nBytes_before );
+        nBytes_before = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
 #endif
         /* lag index */
         encode_absolute_lagIndex = 1;
@@ -149,40 +158,47 @@ void SKP_Silk_encode_parameters_v4(
                 delta_lagIndex = delta_lagIndex + MAX_DELTA_LAG;
                 encode_absolute_lagIndex = 0; /* Only use delta */
             }
-            SKP_Silk_range_encoder( psRC, delta_lagIndex, SKP_Silk_pitch_delta_CDF );
+            ec_encode_bin( psRangeEnc, SKP_Silk_pitch_delta_CDF[ delta_lagIndex ], 
+                SKP_Silk_pitch_delta_CDF[ delta_lagIndex + 1 ], 16 );
         }
         if( encode_absolute_lagIndex ) {
             /* Absolute encoding */
             if( psEncC->fs_kHz == 8 ) {
-                SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_NB_CDF );
+                ec_encode_bin( psRangeEnc, SKP_Silk_pitch_lag_NB_CDF[ psEncCtrlC->lagIndex ], 
+                    SKP_Silk_pitch_lag_NB_CDF[ psEncCtrlC->lagIndex + 1 ], 16 );
             } else if( psEncC->fs_kHz == 12 ) {
-                SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_MB_CDF );
+                ec_encode_bin( psRangeEnc, SKP_Silk_pitch_lag_MB_CDF[ psEncCtrlC->lagIndex ], 
+                    SKP_Silk_pitch_lag_MB_CDF[ psEncCtrlC->lagIndex + 1 ], 16 );
             } else if( psEncC->fs_kHz == 16 ) {
-                SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_WB_CDF );
+                ec_encode_bin( psRangeEnc, SKP_Silk_pitch_lag_WB_CDF[ psEncCtrlC->lagIndex ], 
+                    SKP_Silk_pitch_lag_WB_CDF[ psEncCtrlC->lagIndex + 1 ], 16 );
             } else {
-                SKP_Silk_range_encoder( psRC, psEncCtrlC->lagIndex, SKP_Silk_pitch_lag_SWB_CDF );
+                ec_encode_bin( psRangeEnc, SKP_Silk_pitch_lag_SWB_CDF[ psEncCtrlC->lagIndex ], 
+                    SKP_Silk_pitch_lag_SWB_CDF[ psEncCtrlC->lagIndex + 1 ], 16 );
             }
         }
         psEncC->prev_lagIndex = psEncCtrlC->lagIndex;
 
 #ifdef SAVE_ALL_INTERNAL_DATA
-        SKP_Silk_range_encoder_get_length( psRC, &nBytes_after );
+        nBytes_after = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
         nBytes_lagIndex = nBytes_after - nBytes_before; // bytes just added
 #endif
 
 #ifdef SAVE_ALL_INTERNAL_DATA
-        SKP_Silk_range_encoder_get_length( psRC, &nBytes_before );
+        nBytes_before = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
 #endif
         /* countour index */
         if( psEncC->fs_kHz == 8 ) {
             /* Less codevectors used in 8 khz mode */
-            SKP_Silk_range_encoder( psRC, psEncCtrlC->contourIndex, SKP_Silk_pitch_contour_NB_CDF );
+            ec_encode_bin( psRangeEnc, SKP_Silk_pitch_contour_NB_CDF[ psEncCtrlC->contourIndex ], 
+                SKP_Silk_pitch_contour_NB_CDF[ psEncCtrlC->contourIndex + 1 ], 16 );
         } else {
             /* Joint for 12, 16, 24 khz */
-            SKP_Silk_range_encoder( psRC, psEncCtrlC->contourIndex, SKP_Silk_pitch_contour_CDF );
+            ec_encode_bin( psRangeEnc, SKP_Silk_pitch_contour_CDF[ psEncCtrlC->contourIndex ], 
+                SKP_Silk_pitch_contour_CDF[ psEncCtrlC->contourIndex + 1 ], 16 );
         }
 #ifdef SAVE_ALL_INTERNAL_DATA
-        SKP_Silk_range_encoder_get_length( psRC, &nBytes_after ); 
+        nBytes_after = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
         nBytes_contourIndex = nBytes_after - nBytes_before; // bytes just added
 #endif
 
@@ -190,22 +206,25 @@ void SKP_Silk_encode_parameters_v4(
         /* Encode LTP gains */
         /********************/
 #ifdef SAVE_ALL_INTERNAL_DATA
-        SKP_Silk_range_encoder_get_length( psRC, &nBytes_before );
+        nBytes_before = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
 #endif
         /* PERIndex value */
-        SKP_Silk_range_encoder( psRC, psEncCtrlC->PERIndex, SKP_Silk_LTP_per_index_CDF );
+        ec_encode_bin( psRangeEnc, SKP_Silk_LTP_per_index_CDF[ psEncCtrlC->PERIndex ], 
+            SKP_Silk_LTP_per_index_CDF[ psEncCtrlC->PERIndex + 1 ], 16 );
 
         /* Codebook Indices */
         for( k = 0; k < psEncC->nb_subfr; k++ ) {
-            SKP_Silk_range_encoder( psRC, psEncCtrlC->LTPIndex[ k ], SKP_Silk_LTP_gain_CDF_ptrs[ psEncCtrlC->PERIndex ] );
+            ec_encode_bin( psRangeEnc, SKP_Silk_LTP_gain_CDF_ptrs[ psEncCtrlC->PERIndex ][ psEncCtrlC->LTPIndex[ k ] ], 
+                SKP_Silk_LTP_gain_CDF_ptrs[ psEncCtrlC->PERIndex ][ psEncCtrlC->LTPIndex[ k ] + 1 ], 16 );
         }
 
         /**********************/
         /* Encode LTP scaling */
         /**********************/
-        SKP_Silk_range_encoder( psRC, psEncCtrlC->LTP_scaleIndex, SKP_Silk_LTPscale_CDF );
+        ec_encode_bin( psRangeEnc, SKP_Silk_LTPscale_CDF[ psEncCtrlC->LTP_scaleIndex ], 
+            SKP_Silk_LTPscale_CDF[ psEncCtrlC->LTP_scaleIndex + 1 ], 16 );
 #ifdef SAVE_ALL_INTERNAL_DATA
-        SKP_Silk_range_encoder_get_length( psRC, &nBytes_after );
+        nBytes_after = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
         nBytes_LTP = nBytes_after - nBytes_before; // bytes just added
 #endif
     }
@@ -222,11 +241,12 @@ void SKP_Silk_encode_parameters_v4(
 #endif
 
 #ifdef SAVE_ALL_INTERNAL_DATA
-    SKP_Silk_range_encoder_get_length( psRC, &nBytes_before );
+    nBytes_before = SKP_RSHIFT( ec_enc_tell( psRangeEnc, 0 ) + 7, 3 );
 #endif
 
     /***************/
     /* Encode seed */
     /***************/
-    SKP_Silk_range_encoder( psRC, psEncCtrlC->Seed, SKP_Silk_Seed_CDF );
+    ec_encode_bin( psRangeEnc, SKP_Silk_Seed_CDF[ psEncCtrlC->Seed ], 
+        SKP_Silk_Seed_CDF[ psEncCtrlC->Seed + 1 ], 16 );
 }
diff --git a/src_common/SKP_Silk_encode_pulses.c b/src_common/SKP_Silk_encode_pulses.c
index 82923373f54b47af63bb71223e506abab594dc1c..80ce45308cfcc0bb5d4168c5cf3ca0a60940ae0f 100644
--- a/src_common/SKP_Silk_encode_pulses.c
+++ b/src_common/SKP_Silk_encode_pulses.c
@@ -71,11 +71,11 @@ SKP_INLINE SKP_int combine_and_check(       /* return ok */
 
 /* Encode quantization indices of excitation */
 void SKP_Silk_encode_pulses(
-    SKP_Silk_range_coder_state      *psRC,          /* I/O  Range coder state               */
-    const SKP_int                   sigtype,        /* I    Sigtype                         */
-    const SKP_int                   QuantOffsetType,/* I    QuantOffsetType                 */
-    SKP_int8                        q[],            /* I    quantization indices            */
-    const SKP_int                   frame_length    /* I    Frame length                    */
+    ec_enc                      *psRangeEnc,        /* I/O  compressor data structure                   */
+    const SKP_int               sigtype,            /* I    Sigtype                                     */
+    const SKP_int               QuantOffsetType,    /* I    QuantOffsetType                             */
+    SKP_int8                    q[],                /* I    quantization indices                        */
+    const SKP_int               frame_length        /* I    Frame length                                */
 )
 {
     SKP_int   i, k, j, iter, bit, nLS, scale_down, RateLevelIndex = 0;
@@ -167,7 +167,8 @@ void SKP_Silk_encode_pulses(
             RateLevelIndex = k;
         }
     }
-    SKP_Silk_range_encoder( psRC, RateLevelIndex, SKP_Silk_rate_levels_CDF[ sigtype ] );
+    ec_encode_bin( psRangeEnc, SKP_Silk_rate_levels_CDF[ sigtype ][ RateLevelIndex ], 
+        SKP_Silk_rate_levels_CDF[ sigtype ][ RateLevelIndex + 1 ], 16 );
 
     /***************************************************/
     /* Sum-Weighted-Pulses Encoding                    */
@@ -175,13 +176,15 @@ void SKP_Silk_encode_pulses(
     cdf_ptr = SKP_Silk_pulses_per_block_CDF[ RateLevelIndex ];
     for( i = 0; i < iter; i++ ) {
         if( nRshifts[ i ] == 0 ) {
-            SKP_Silk_range_encoder( psRC, sum_pulses[ i ], cdf_ptr );
+            ec_encode_bin( psRangeEnc, cdf_ptr[ sum_pulses[ i ] ], cdf_ptr[ sum_pulses[ i ] + 1 ], 16 );
         } else {
-            SKP_Silk_range_encoder( psRC, MAX_PULSES + 1, cdf_ptr );
+            ec_encode_bin( psRangeEnc, cdf_ptr[ MAX_PULSES + 1 ], cdf_ptr[ MAX_PULSES + 2 ], 16 );
             for( k = 0; k < nRshifts[ i ] - 1; k++ ) {
-                SKP_Silk_range_encoder( psRC, MAX_PULSES + 1, SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ] );
+                ec_encode_bin( psRangeEnc, SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ][ sum_pulses[ i ] ], 
+                    SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ][ sum_pulses[ i ] + 1 ], 16 );
             }
-            SKP_Silk_range_encoder( psRC, sum_pulses[ i ], SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ] );
+            ec_encode_bin( psRangeEnc, SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ][ sum_pulses[ i ] ], 
+                SKP_Silk_pulses_per_block_CDF[ N_RATE_LEVELS - 1 ][ sum_pulses[ i ] + 1 ], 16 );
         }
     }
 
@@ -190,7 +193,7 @@ void SKP_Silk_encode_pulses(
     /******************/
     for( i = 0; i < iter; i++ ) {
         if( sum_pulses[ i ] > 0 ) {
-            SKP_Silk_shell_encoder( psRC, &abs_pulses[ i * SHELL_CODEC_FRAME_LENGTH ] );
+            SKP_Silk_shell_encoder( psRangeEnc, &abs_pulses[ i * SHELL_CODEC_FRAME_LENGTH ] );
         }
     }
 
@@ -205,10 +208,10 @@ void SKP_Silk_encode_pulses(
                 abs_q = (SKP_int8)SKP_abs( pulses_ptr[ k ] );
                 for( j = nLS; j > 0; j-- ) {
                     bit = SKP_RSHIFT( abs_q, j ) & 1;
-                    SKP_Silk_range_encoder( psRC, bit, SKP_Silk_lsb_CDF );
+                    ec_enc_bit_prob( psRangeEnc, bit, 65536 - SKP_Silk_lsb_CDF[ 1 ] );
                 }
                 bit = abs_q & 1;
-                SKP_Silk_range_encoder( psRC, bit, SKP_Silk_lsb_CDF );
+                ec_enc_bit_prob( psRangeEnc, bit, 65536 - SKP_Silk_lsb_CDF[ 1 ] );
             }
         }
     }
@@ -217,6 +220,6 @@ void SKP_Silk_encode_pulses(
     /****************/
     /* Encode signs */
     /****************/
-    SKP_Silk_encode_signs( psRC, q, frame_length, sigtype, QuantOffsetType, RateLevelIndex );
+    SKP_Silk_encode_signs( psRangeEnc, q, frame_length, sigtype, QuantOffsetType, RateLevelIndex );
 #endif
 }
diff --git a/src_common/SKP_Silk_main.h b/src_common/SKP_Silk_main.h
index eddcddc72ca651a134bc364d29452aa5e0a90174..f9610cfe12920147ec5b54002ad880a33391b67a 100644
--- a/src_common/SKP_Silk_main.h
+++ b/src_common/SKP_Silk_main.h
@@ -44,7 +44,7 @@ extern "C"
 
 /* Encodes signs of excitation */
 void SKP_Silk_encode_signs(
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */
+    ec_enc                      *psRangeEnc,        /* I/O  Compressor data structure                   */
     const SKP_int8              q[],                /* I    pulse signal                                */
     const SKP_int               length,             /* I    length of input                             */
     const SKP_int               sigtype,            /* I    Signal type                                 */
@@ -54,7 +54,7 @@ void SKP_Silk_encode_signs(
 
 /* Decodes signs of excitation */
 void SKP_Silk_decode_signs(
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */
+    ec_dec                      *psRangeDec,        /* I/O  Compressor data structure                   */
     SKP_int                     q[],                /* I/O  pulse signal                                */
     const SKP_int               length,             /* I    length of output                            */
     const SKP_int               sigtype,            /* I    Signal type                                 */
@@ -68,7 +68,7 @@ void SKP_Silk_decode_signs(
 
 /* Encode quantization indices of excitation */
 void SKP_Silk_encode_pulses(
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */
+    ec_enc                      *psRangeEnc,        /* I/O  compressor data structure                   */
     const SKP_int               sigtype,            /* I    Sigtype                                     */
     const SKP_int               QuantOffsetType,    /* I    QuantOffsetType                             */
     SKP_int8                    q[],                /* I    quantization indices                        */
@@ -77,95 +77,28 @@ void SKP_Silk_encode_pulses(
 
 /* Shell encoder, operates on one shell code frame of 16 pulses */
 void SKP_Silk_shell_encoder(
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */
+    ec_enc                      *psRangeEnc,        /* I/O  compressor data structure                   */
     const SKP_int               *pulses0            /* I    data: nonnegative pulse amplitudes          */
 );
 
 /* Shell decoder, operates on one shell code frame of 16 pulses */
 void SKP_Silk_shell_decoder(
     SKP_int                     *pulses0,           /* O    data: nonnegative pulse amplitudes          */
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */
+    ec_dec                      *psRangeDec,        /* I/O  Compressor data structure                   */
     const SKP_int               pulses4             /* I    number of pulses per pulse-subframe         */
 );
 
 /***************/
 /* Range coder */
 /***************/
-/* Range encoder for one symbol */
-void SKP_Silk_range_encoder(
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */
-    const SKP_int               data,               /* I    uncompressed data                           */
-    const SKP_uint16            prob[]              /* I    cumulative density functions                */
-);
-    
-/* Range encoder for one symbol, with uniform PDF*/
-void SKP_Silk_range_encode_uniform(
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */
-    const SKP_int                   data,               /* I    uncompressed data                           */
-    const SKP_int                   N                   /* I    number of possible outcomes                 */
-);
-
-/* Range encoder for multiple symbols */
-void SKP_Silk_range_encoder_multi(
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */
-    const SKP_int               data[],             /* I    uncompressed data    [nSymbols]             */
-    const SKP_uint16 * const    prob[],             /* I    cumulative density functions                */
-    const SKP_int               nSymbols            /* I    number of data symbols                      */
-);
-
 /* Range decoder for one symbol */
 void SKP_Silk_range_decoder(
     SKP_int                     data[],             /* O    uncompressed data                           */
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */
+    ec_dec                      *psRangeDec,        /* I/O  Compressor data structure                   */
     const SKP_uint16            prob[],             /* I    cumulative density function                 */
     SKP_int                     probIx              /* I    initial (middle) entry of cdf               */
 );
 
-/* Range decoder for one symbol, with uniform PDF*/
-void SKP_Silk_range_decode_uniform(
-    SKP_int                         data[],             /* O    uncompressed data                           */
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */
-    const SKP_int                   N                   /* I    number of possible outcomes                 */
-);
-
-/* Range decoder for multiple symbols */
-void SKP_Silk_range_decoder_multi(
-    SKP_int                     data[],             /* O    uncompressed data                [nSymbols] */
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  compressor data structure                   */
-    const SKP_uint16 * const    prob[],             /* I    cumulative density functions                */
-    const SKP_int               probStartIx[],      /* I    initial (middle) entries of cdfs [nSymbols] */
-    const SKP_int               nSymbols            /* I    number of data symbols                      */
-);
-
-/* Initialize range coder structure for encoder */
-void SKP_Silk_range_enc_init(
-    SKP_Silk_range_coder_state  *psRC               /* O    compressor data structure                   */
-);
-
-/* Initialize range coder structure for decoder */
-void SKP_Silk_range_dec_init(
-    SKP_Silk_range_coder_state  *psRC,              /* O    compressor data structure                   */
-    const SKP_uint8             buffer[],           /* I    buffer for compressed data [bufferLength]   */
-    const SKP_int32             bufferLength        /* I    buffer length (in bytes)                    */
-);
-
-/* Determine length of bitstream */
-SKP_int SKP_Silk_range_encoder_get_length(          /* O    returns number of BITS in stream            */
-    SKP_Silk_range_coder_state          *psRC,      /* I    compressed data structure                   */
-    SKP_int                             *nBytes     /* O    number of BYTES in stream                   */
-);
-
-/* Determine length of bitstream */
-SKP_int SKP_Silk_range_decoder_get_length(          /* O    returns number of BITS in stream            */
-    SKP_Silk_range_coder_state          *psRC,      /* I    compressed data structure                   */
-    SKP_int                             *nBytes     /* O    number of BYTES in stream                   */
-);
-
-/* Check that any remaining bits in the last byte are set to 1 */
-void SKP_Silk_range_coder_check_after_decoding(
-    SKP_Silk_range_coder_state  *psRC               /* I/O  compressed data structure                   */
-);
-
 /* Gain scalar quantization with hysteresis, uniform on log scale */
 void SKP_Silk_gains_quant(
     SKP_int                         ind[ MAX_NB_SUBFR ],        /* O    gain indices                            */
@@ -311,23 +244,25 @@ void SKP_Silk_decoder_set_fs(
 /****************/
 SKP_int SKP_Silk_decode_frame(
     SKP_Silk_decoder_state      *psDec,             /* I/O  Pointer to Silk decoder state               */
+    ec_dec                      *psRangeDec,        /* I/O  Compressor data structure                   */
     SKP_int16                   pOut[],             /* O    Pointer to output speech frame              */
     SKP_int16                   *pN,                /* O    Pointer to size of output frame             */
-    const SKP_uint8             pCode[],            /* I    Pointer to payload                          */
     const SKP_int               nBytes,             /* I    Payload length                              */
     SKP_int                     action,             /* I    Action from Jitter Buffer                   */
     SKP_int                     *decBytes           /* O    Used bytes to decode this frame             */
 );
 
 /* Decode indices from payload v4 Bitstream */
-void SKP_Silk_decode_indices_v4(
-    SKP_Silk_decoder_state      *psDec              /* I/O  State                                       */
+void SKP_Silk_decode_indices(
+    SKP_Silk_decoder_state      *psDec,             /* I/O  State                                       */
+    ec_dec                      *psRangeDec         /* I/O  Compressor data structure                   */
 );
 
 /* Decode parameters from payload v4 Bitstream */
-void SKP_Silk_decode_parameters_v4(
+void SKP_Silk_decode_parameters(
     SKP_Silk_decoder_state      *psDec,                                 /* I/O  State                                    */
     SKP_Silk_decoder_control    *psDecCtrl,                             /* I/O  Decoder control                          */
+    ec_dec                      *psRangeDec,                            /* I/O  Compressor data structure                */
     SKP_int                     q[ MAX_FRAME_LENGTH ],                  /* O    Excitation signal                        */
     const SKP_int               fullDecoding                            /* I    Flag to tell if only arithmetic decoding */
 );
@@ -354,7 +289,7 @@ void SKP_Silk_NLSF_MSVQ_decode(
 
 /* Decode quantization indices of excitation (Shell coding) */
 void SKP_Silk_decode_pulses(
-    SKP_Silk_range_coder_state  *psRC,              /* I/O  Range coder state                           */
+    ec_dec                      *psRangeDec,        /* I/O  Compressor data structure                   */
     SKP_Silk_decoder_control    *psDecCtrl,         /* I/O  Decoder control                             */
     SKP_int                     q[],                /* O    Excitation signal                           */
     const SKP_int               frame_length        /* I    Frame length (preliminary)                  */
@@ -378,10 +313,10 @@ void SKP_Silk_CNG(
 );
 
 /* Encoding of various parameters */
-void SKP_Silk_encode_parameters_v4(
+void SKP_Silk_encode_parameters(
     SKP_Silk_encoder_state      *psEncC,            /* I/O  Encoder state                               */
     SKP_Silk_encoder_control    *psEncCtrlC,        /* I/O  Encoder control                             */
-    SKP_Silk_range_coder_state  *psRC               /* I/O  Range encoder state                         */
+    ec_enc                      *psRangeEnc         /* I/O  Compressor data structure                   */
 );
 
 /* Extract lowest layer encoding */
diff --git a/src_common/SKP_Silk_range_coder.c b/src_common/SKP_Silk_range_coder.c
index a9dcc7ed56bd3f65c6564c60fd86735fa1f82e08..b731f1912fcc5875ea60212b94764a348d3a429e 100644
--- a/src_common/SKP_Silk_range_coder.c
+++ b/src_common/SKP_Silk_range_coder.c
@@ -27,77 +27,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include "SKP_Silk_main.h"
 
-#define MAX_SIZE 10000
-
-/* Range encoder for one symbol */
-void SKP_Silk_range_encoder(
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */
-    const SKP_int                   data,               /* I    uncompressed data                           */
-    const SKP_uint16                prob[]              /* I    cumulative density functions                */
-)
-{
-    SKP_uint32 low_Q16, high_Q16;
-
-    if( psRC->error ) {
-        return;
-    }
-    low_Q16  = prob[ data ];
-    high_Q16 = prob[ data + 1 ];
-    
-#ifdef SAVE_ALL_INTERNAL_DATA
-    DEBUG_STORE_DATA( enc_l.dat, &low_Q16,  sizeof(SKP_uint32) );
-    DEBUG_STORE_DATA( enc_h.dat, &high_Q16, sizeof(SKP_uint32) );
-    DEBUG_STORE_DATA( enc.dat,   &data,     sizeof(SKP_int) );
-#endif
-
-    if( prob[ 2 ] == 65535 ) {
-        /* Instead of detection, we could add a separate function and call when we know that input is a bit */
-        ec_enc_bit_prob( &psRC->range_enc_celt_state, data, 65536 - prob[ 1 ] );
-    } else {
-        ec_encode_bin( &psRC->range_enc_celt_state, low_Q16, high_Q16, 16 );
-    }
-}
-
-/* Range encoder for one symbol, with uniform PDF*/
-void SKP_Silk_range_encode_uniform(
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */
-    const SKP_int                   data,               /* I    uncompressed data                           */
-    const SKP_int                   N                   /* I    number of possible outcomes                 */
-)
-{
-    SKP_int i;
-    SKP_uint16 delta, prob[ MAX_SIZE + 1 ];
-
-    SKP_assert( N < MAX_SIZE );
-
-    delta = ( SKP_uint16 )SKP_DIV32_16( 65535, N );
-    prob[ 0 ] = 0;
-    for( i = 0; i < N - 1; i++ ) {
-        prob[ i + 1 ] = prob[ i ] + delta;
-    }
-    prob[ N ] = 65535;
-
-    SKP_Silk_range_encoder( psRC, data, prob );
-}
-
-/* Range encoder for multiple symbols */
-void SKP_Silk_range_encoder_multi(
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */
-    const SKP_int                   data[],             /* I    uncompressed data    [nSymbols]             */
-    const SKP_uint16 * const        prob[],             /* I    cumulative density functions                */
-    const SKP_int                   nSymbols            /* I    number of data symbols                      */
-)
-{
-    SKP_int k;
-    for( k = 0; k < nSymbols; k++ ) {
-        SKP_Silk_range_encoder( psRC, data[ k ], prob[ k ] );
-    }
-}
-
 /* Range decoder for one symbol */
 void SKP_Silk_range_decoder(
     SKP_int                         data[],             /* O    uncompressed data                           */
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */
+    ec_dec                          *psRangeDec,        /* I/O  Compressor data structure                   */
     const SKP_uint16                prob[],             /* I    cumulative density function                 */
     SKP_int                         probIx              /* I    initial (middle) entry of cdf               */
 )
@@ -107,21 +40,12 @@ void SKP_Silk_range_decoder(
     SKP_uint32 low_Q16_returned;
     SKP_int    temp;
 
-    if( psRC->error ) {
-        /* Set output to zero */
-        *data = 0;
-        return;
-    }
-
     if( prob[ 2 ] == 65535 ) {
         /* Instead of detection, we could add a separate function and call when we know that output is a bit */
-        *data = ec_dec_bit_prob( &psRC->range_dec_celt_state, 65536 - prob[ 1 ] );
+        *data = ec_dec_bit_prob( psRangeDec, 65536 - prob[ 1 ] );
     } else {
-        low_Q16_returned = ec_decode_bin( &psRC->range_dec_celt_state, 16 );
-    }
+        low_Q16_returned = ec_decode_bin( psRangeDec, 16 );
 
-    /* OPTIMIZE ME WITH BI-SECTION */
-    if( prob[ 2 ] != 65535 ) {
 #if 1
         temp = 0;
         while( low_Q16_returned >= prob[ ++temp ] ) {}
@@ -150,141 +74,9 @@ void SKP_Silk_range_decoder(
         DEBUG_STORE_DATA( dec_l.dat,  &low_Q16,           sizeof( SKP_uint32 ) );
         DEBUG_STORE_DATA( dec_h.dat,  &high_Q16,          sizeof( SKP_uint32 ) );
 #endif  
-        ec_dec_update( &psRC->range_dec_celt_state, low_Q16, high_Q16,( 1 << 16 ) );
+        ec_dec_update( psRangeDec, low_Q16, high_Q16,( 1 << 16 ) );
     }
 #ifdef SAVE_ALL_INTERNAL_DATA
     DEBUG_STORE_DATA( dec.dat, data, sizeof( SKP_int ) );
 #endif
 }
-
-/* Range decoder for one symbol, with uniform PDF*/
-void SKP_Silk_range_decode_uniform(
-    SKP_int                         data[],             /* O    uncompressed data                           */
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */
-    const SKP_int                   N                   /* I    number of possible outcomes                 */
-)
-{
-    SKP_int i;
-    SKP_uint16 delta, prob[ MAX_SIZE + 1 ];
-
-    SKP_assert( N < MAX_SIZE );
-
-    delta = ( SKP_uint16 )SKP_DIV32_16( 65535, N );
-    prob[ 0 ] = 0;
-    for( i = 0; i < N - 1; i++ ) {
-        prob[ i + 1 ] = prob[ i ] + delta;
-    }
-    prob[ N ] = 65535;
-
-    SKP_Silk_range_decoder( data, psRC, prob, ( N >> 1 ) );
-}
-
-/* Range decoder for multiple symbols */
-void SKP_Silk_range_decoder_multi(
-    SKP_int                         data[],             /* O    uncompressed data                [nSymbols] */
-    SKP_Silk_range_coder_state      *psRC,              /* I/O  compressor data structure                   */
-    const SKP_uint16 * const        prob[],             /* I    cumulative density functions                */
-    const SKP_int                   probStartIx[],      /* I    initial (middle) entries of cdfs [nSymbols] */
-    const SKP_int                   nSymbols            /* I    number of data symbols                      */
-)
-{
-    SKP_int k;
-    for( k = 0; k < nSymbols; k++ ) {
-        SKP_Silk_range_decoder( &data[ k ], psRC, prob[ k ], probStartIx[ k ] );
-    }
-}
-
-/* Initialize range encoder */
-void SKP_Silk_range_enc_init(
-    SKP_Silk_range_coder_state      *psRC               /* O    compressor data structure                   */
-)
-{
-    psRC->error        = 0;
-}
-
-/* Initialize range decoder */
-void SKP_Silk_range_dec_init(
-    SKP_Silk_range_coder_state      *psRC,              /* O    compressor data structure                   */
-    const SKP_uint8                 buffer[],           /* I    buffer for compressed data [bufferLength]   */
-    const SKP_int32                 bufferLength        /* I    buffer length (in bytes)                    */
-)
-{
-    /* check input */
-    if( bufferLength > MAX_ARITHM_BYTES ) {
-        psRC->error = RANGE_CODER_DEC_PAYLOAD_TOO_LONG;
-        return;
-    }
-    /* Initialize structure */
-    /* Copy to internal buffer */
-    SKP_memcpy( psRC->buffer, buffer, bufferLength * sizeof( SKP_uint8 ) ); 
-    psRC->bufferLength = bufferLength;
-    psRC->bufferIx = 0;
-    psRC->base_Q32 = 
-        SKP_LSHIFT_uint( ( SKP_uint32 )buffer[ 0 ], 24 ) | 
-        SKP_LSHIFT_uint( ( SKP_uint32 )buffer[ 1 ], 16 ) | 
-        SKP_LSHIFT_uint( ( SKP_uint32 )buffer[ 2 ],  8 ) | 
-                         ( SKP_uint32 )buffer[ 3 ];
-    psRC->range_Q16 = 0x0000FFFF;
-    psRC->error     = 0;
-}
-
-/* Determine length of bitstream */
-SKP_int SKP_Silk_range_encoder_get_length(              /* O    returns number of BITS in stream            */
-    SKP_Silk_range_coder_state          *psRC,          /* I    compressed data structure                   */
-    SKP_int                             *nBytes         /* O    number of BYTES in stream                   */
-)
-{
-    SKP_int nBits;
-
-    /* Get number of bits in bitstream */
-    nBits = ec_enc_tell( &psRC->range_enc_celt_state, 0 );
-
-    /* Round up to an integer number of bytes */
-    *nBytes = SKP_RSHIFT( nBits + 7, 3 );
-
-    /* Return number of bits in bitstream */
-    return nBits;
-}
-
-/* Determine length of bitstream */
-SKP_int SKP_Silk_range_decoder_get_length(              /* O    returns number of BITS in stream            */
-    SKP_Silk_range_coder_state          *psRC,          /* I    compressed data structure                   */
-    SKP_int                             *nBytes         /* O    number of BYTES in stream                   */
-)
-{
-    SKP_int nBits;
-
-    /* Get number of bits in bitstream */
-    nBits = ec_dec_tell( &psRC->range_dec_celt_state, 0 );
-
-    /* Round up to an integer number of bytes */
-    *nBytes = SKP_RSHIFT( nBits + 7, 3 );
-
-    /* Return number of bits in bitstream */
-    return nBits;
-}
-
-/* Check that any remaining bits in the last byte are set to 1 */
-void SKP_Silk_range_coder_check_after_decoding(
-    SKP_Silk_range_coder_state      *psRC               /* I/O  compressed data structure                   */
-)
-{
-    SKP_int bits_in_stream, nBytes, mask;
-
-    bits_in_stream = SKP_Silk_range_decoder_get_length( psRC, &nBytes );
-
-    /* Make sure not to read beyond buffer */
-    if( nBytes - 1 >= psRC->range_dec_celt_state.buf->storage ) {
-        psRC->error = RANGE_CODER_DECODER_CHECK_FAILED;
-        return;
-    }
-
-    /* Test any remaining bits in last byte */
-    if( bits_in_stream & 7 ) {
-        mask = SKP_RSHIFT( 0xFF, bits_in_stream & 7 );
-        if( ( psRC->range_dec_celt_state.buf->buf[ nBytes - 1 ] & mask ) != mask ) {
-            psRC->error = RANGE_CODER_DECODER_CHECK_FAILED;
-            return;
-        }
-    }
-}
diff --git a/src_common/SKP_Silk_shell_coder.c b/src_common/SKP_Silk_shell_coder.c
index 8e395822ba9aa09007c978818923c677108d4de8..15a2628b2d361670a27e43dee20504db65deaf48 100644
--- a/src_common/SKP_Silk_shell_coder.c
+++ b/src_common/SKP_Silk_shell_coder.c
@@ -42,7 +42,7 @@ SKP_INLINE void combine_pulses(
 }
 
 SKP_INLINE void encode_split(
-    SKP_Silk_range_coder_state  *sRC,           /* I/O: compressor data structure                   */
+    ec_enc                      *psRangeEnc,    /* I/O  compressor data structure                   */
     const SKP_int               p_child1,       /* I:   pulse amplitude of first child subframe     */
     const SKP_int               p,              /* I:   pulse amplitude of current subframe         */
     const SKP_uint16            *shell_table    /* I:   table of shell cdfs                         */
@@ -52,14 +52,18 @@ SKP_INLINE void encode_split(
 
     if( p > 0 ) {
         cdf = &shell_table[ SKP_Silk_shell_code_table_offsets[ p ] ];
-        SKP_Silk_range_encoder( sRC, p_child1, cdf );
+        if( cdf[ 2 ] == 65535 ) {
+            ec_enc_bit_prob( psRangeEnc, p_child1, 65536 - cdf[ 1 ] );
+        } else {
+            ec_encode_bin( psRangeEnc, cdf[ p_child1 ], cdf[ p_child1 + 1 ], 16 );
+        }
     }
 }
 
 SKP_INLINE void decode_split(
     SKP_int                     *p_child1,      /* O:   pulse amplitude of first child subframe     */
     SKP_int                     *p_child2,      /* O:   pulse amplitude of second child subframe    */
-    SKP_Silk_range_coder_state  *sRC,           /* I/O: compressor data structure                   */
+    ec_dec                      *psRangeDec,    /* I/O  Compressor data structure                   */
     const SKP_int               p,              /* I:   pulse amplitude of current subframe         */
     const SKP_uint16            *shell_table    /* I:   table of shell cdfs                         */
 )
@@ -70,7 +74,7 @@ SKP_INLINE void decode_split(
     if( p > 0 ) {
         cdf_middle = SKP_RSHIFT( p, 1 );
         cdf = &shell_table[ SKP_Silk_shell_code_table_offsets[ p ] ];
-        SKP_Silk_range_decoder( p_child1, sRC, cdf, cdf_middle );
+        SKP_Silk_range_decoder( p_child1, psRangeDec, cdf, cdf_middle );
         p_child2[ 0 ] = p - p_child1[ 0 ];
     } else {
         p_child1[ 0 ] = 0;
@@ -80,8 +84,8 @@ SKP_INLINE void decode_split(
 
 /* Shell encoder, operates on one shell code frame of 16 pulses */
 void SKP_Silk_shell_encoder(
-    SKP_Silk_range_coder_state      *sRC,               /* I/O  compressor data structure                   */
-    const SKP_int                   *pulses0            /* I    data: nonnegative pulse amplitudes          */
+    ec_enc                      *psRangeEnc,        /* I/O  compressor data structure                   */
+    const SKP_int               *pulses0            /* I    data: nonnegative pulse amplitudes          */
 )
 {
     SKP_int pulses1[ 8 ], pulses2[ 4 ], pulses3[ 2 ], pulses4[ 1 ];
@@ -95,34 +99,34 @@ void SKP_Silk_shell_encoder(
     combine_pulses( pulses3, pulses2, 2 );
     combine_pulses( pulses4, pulses3, 1 );
 
-    encode_split( sRC, pulses3[  0 ], pulses4[ 0 ], SKP_Silk_shell_code_table3 );
+    encode_split( psRangeEnc, pulses3[  0 ], pulses4[ 0 ], SKP_Silk_shell_code_table3 );
 
-    encode_split( sRC, pulses2[  0 ], pulses3[ 0 ], SKP_Silk_shell_code_table2 );
+    encode_split( psRangeEnc, pulses2[  0 ], pulses3[ 0 ], SKP_Silk_shell_code_table2 );
 
-    encode_split( sRC, pulses1[  0 ], pulses2[ 0 ], SKP_Silk_shell_code_table1 );
-    encode_split( sRC, pulses0[  0 ], pulses1[ 0 ], SKP_Silk_shell_code_table0 );
-    encode_split( sRC, pulses0[  2 ], pulses1[ 1 ], SKP_Silk_shell_code_table0 );
+    encode_split( psRangeEnc, pulses1[  0 ], pulses2[ 0 ], SKP_Silk_shell_code_table1 );
+    encode_split( psRangeEnc, pulses0[  0 ], pulses1[ 0 ], SKP_Silk_shell_code_table0 );
+    encode_split( psRangeEnc, pulses0[  2 ], pulses1[ 1 ], SKP_Silk_shell_code_table0 );
 
-    encode_split( sRC, pulses1[  2 ], pulses2[ 1 ], SKP_Silk_shell_code_table1 );
-    encode_split( sRC, pulses0[  4 ], pulses1[ 2 ], SKP_Silk_shell_code_table0 );
-    encode_split( sRC, pulses0[  6 ], pulses1[ 3 ], SKP_Silk_shell_code_table0 );
+    encode_split( psRangeEnc, pulses1[  2 ], pulses2[ 1 ], SKP_Silk_shell_code_table1 );
+    encode_split( psRangeEnc, pulses0[  4 ], pulses1[ 2 ], SKP_Silk_shell_code_table0 );
+    encode_split( psRangeEnc, pulses0[  6 ], pulses1[ 3 ], SKP_Silk_shell_code_table0 );
 
-    encode_split( sRC, pulses2[  2 ], pulses3[ 1 ], SKP_Silk_shell_code_table2 );
+    encode_split( psRangeEnc, pulses2[  2 ], pulses3[ 1 ], SKP_Silk_shell_code_table2 );
 
-    encode_split( sRC, pulses1[  4 ], pulses2[ 2 ], SKP_Silk_shell_code_table1 );
-    encode_split( sRC, pulses0[  8 ], pulses1[ 4 ], SKP_Silk_shell_code_table0 );
-    encode_split( sRC, pulses0[ 10 ], pulses1[ 5 ], SKP_Silk_shell_code_table0 );
+    encode_split( psRangeEnc, pulses1[  4 ], pulses2[ 2 ], SKP_Silk_shell_code_table1 );
+    encode_split( psRangeEnc, pulses0[  8 ], pulses1[ 4 ], SKP_Silk_shell_code_table0 );
+    encode_split( psRangeEnc, pulses0[ 10 ], pulses1[ 5 ], SKP_Silk_shell_code_table0 );
 
-    encode_split( sRC, pulses1[  6 ], pulses2[ 3 ], SKP_Silk_shell_code_table1 );
-    encode_split( sRC, pulses0[ 12 ], pulses1[ 6 ], SKP_Silk_shell_code_table0 );
-    encode_split( sRC, pulses0[ 14 ], pulses1[ 7 ], SKP_Silk_shell_code_table0 );
+    encode_split( psRangeEnc, pulses1[  6 ], pulses2[ 3 ], SKP_Silk_shell_code_table1 );
+    encode_split( psRangeEnc, pulses0[ 12 ], pulses1[ 6 ], SKP_Silk_shell_code_table0 );
+    encode_split( psRangeEnc, pulses0[ 14 ], pulses1[ 7 ], SKP_Silk_shell_code_table0 );
 }
 
 
 /* Shell decoder, operates on one shell code frame of 16 pulses */
 void SKP_Silk_shell_decoder(
     SKP_int                         *pulses0,           /* O    data: nonnegative pulse amplitudes          */
-    SKP_Silk_range_coder_state      *sRC,               /* I/O  compressor data structure                   */
+    ec_dec                          *psRangeDec,        /* I/O  Compressor data structure                   */
     const SKP_int                   pulses4             /* I    number of pulses per pulse-subframe         */
 )
 {
@@ -131,25 +135,25 @@ void SKP_Silk_shell_decoder(
     /* this function operates on one shell code frame of 16 pulses */
     SKP_assert( SHELL_CODEC_FRAME_LENGTH == 16 );
 
-    decode_split( &pulses3[  0 ], &pulses3[  1 ], sRC, pulses4,      SKP_Silk_shell_code_table3 );
+    decode_split( &pulses3[  0 ], &pulses3[  1 ], psRangeDec, pulses4,      SKP_Silk_shell_code_table3 );
 
-    decode_split( &pulses2[  0 ], &pulses2[  1 ], sRC, pulses3[ 0 ], SKP_Silk_shell_code_table2 );
+    decode_split( &pulses2[  0 ], &pulses2[  1 ], psRangeDec, pulses3[ 0 ], SKP_Silk_shell_code_table2 );
 
-    decode_split( &pulses1[  0 ], &pulses1[  1 ], sRC, pulses2[ 0 ], SKP_Silk_shell_code_table1 );
-    decode_split( &pulses0[  0 ], &pulses0[  1 ], sRC, pulses1[ 0 ], SKP_Silk_shell_code_table0 );
-    decode_split( &pulses0[  2 ], &pulses0[  3 ], sRC, pulses1[ 1 ], SKP_Silk_shell_code_table0 );
+    decode_split( &pulses1[  0 ], &pulses1[  1 ], psRangeDec, pulses2[ 0 ], SKP_Silk_shell_code_table1 );
+    decode_split( &pulses0[  0 ], &pulses0[  1 ], psRangeDec, pulses1[ 0 ], SKP_Silk_shell_code_table0 );
+    decode_split( &pulses0[  2 ], &pulses0[  3 ], psRangeDec, pulses1[ 1 ], SKP_Silk_shell_code_table0 );
 
-    decode_split( &pulses1[  2 ], &pulses1[  3 ], sRC, pulses2[ 1 ], SKP_Silk_shell_code_table1 );
-    decode_split( &pulses0[  4 ], &pulses0[  5 ], sRC, pulses1[ 2 ], SKP_Silk_shell_code_table0 );
-    decode_split( &pulses0[  6 ], &pulses0[  7 ], sRC, pulses1[ 3 ], SKP_Silk_shell_code_table0 );
+    decode_split( &pulses1[  2 ], &pulses1[  3 ], psRangeDec, pulses2[ 1 ], SKP_Silk_shell_code_table1 );
+    decode_split( &pulses0[  4 ], &pulses0[  5 ], psRangeDec, pulses1[ 2 ], SKP_Silk_shell_code_table0 );
+    decode_split( &pulses0[  6 ], &pulses0[  7 ], psRangeDec, pulses1[ 3 ], SKP_Silk_shell_code_table0 );
 
-    decode_split( &pulses2[  2 ], &pulses2[  3 ], sRC, pulses3[ 1 ], SKP_Silk_shell_code_table2 );
+    decode_split( &pulses2[  2 ], &pulses2[  3 ], psRangeDec, pulses3[ 1 ], SKP_Silk_shell_code_table2 );
 
-    decode_split( &pulses1[  4 ], &pulses1[  5 ], sRC, pulses2[ 2 ], SKP_Silk_shell_code_table1 );
-    decode_split( &pulses0[  8 ], &pulses0[  9 ], sRC, pulses1[ 4 ], SKP_Silk_shell_code_table0 );
-    decode_split( &pulses0[ 10 ], &pulses0[ 11 ], sRC, pulses1[ 5 ], SKP_Silk_shell_code_table0 );
+    decode_split( &pulses1[  4 ], &pulses1[  5 ], psRangeDec, pulses2[ 2 ], SKP_Silk_shell_code_table1 );
+    decode_split( &pulses0[  8 ], &pulses0[  9 ], psRangeDec, pulses1[ 4 ], SKP_Silk_shell_code_table0 );
+    decode_split( &pulses0[ 10 ], &pulses0[ 11 ], psRangeDec, pulses1[ 5 ], SKP_Silk_shell_code_table0 );
 
-    decode_split( &pulses1[  6 ], &pulses1[  7 ], sRC, pulses2[ 3 ], SKP_Silk_shell_code_table1 );
-    decode_split( &pulses0[ 12 ], &pulses0[ 13 ], sRC, pulses1[ 6 ], SKP_Silk_shell_code_table0 );
-    decode_split( &pulses0[ 14 ], &pulses0[ 15 ], sRC, pulses1[ 7 ], SKP_Silk_shell_code_table0 );
+    decode_split( &pulses1[  6 ], &pulses1[  7 ], psRangeDec, pulses2[ 3 ], SKP_Silk_shell_code_table1 );
+    decode_split( &pulses0[ 12 ], &pulses0[ 13 ], psRangeDec, pulses1[ 6 ], SKP_Silk_shell_code_table0 );
+    decode_split( &pulses0[ 14 ], &pulses0[ 15 ], psRangeDec, pulses1[ 7 ], SKP_Silk_shell_code_table0 );
 }
diff --git a/src_common/SKP_Silk_structs.h b/src_common/SKP_Silk_structs.h
index cd6ed253a0b991786fc861ef4cfe992c70b85673..13e2ae60e9a04be9b398232a967f448b1826d01a 100644
--- a/src_common/SKP_Silk_structs.h
+++ b/src_common/SKP_Silk_structs.h
@@ -83,6 +83,7 @@ typedef struct {
 /*******************************/
 /* Range encoder/decoder state */
 /*******************************/
+#if 0
 typedef struct {
     SKP_int32   bufferLength;
     SKP_int32   bufferIx;
@@ -90,10 +91,10 @@ typedef struct {
     SKP_uint32  range_Q16;
     SKP_int32   error;
     SKP_uint8   buffer[ MAX_ARITHM_BYTES ];     /* Buffer containing payload                                */
-    /* The CELT entropy encoder + decoder */
-    ec_enc      range_enc_celt_state;
+    /* The CELT entropy decoder */
     ec_dec      range_dec_celt_state;
 } SKP_Silk_range_coder_state;
+#endif
 
 /* Input frequency range detection struct */
 typedef struct {
@@ -138,8 +139,8 @@ typedef struct {
 /* Encoder state                */
 /********************************/
 typedef struct {
-    SKP_Silk_range_coder_state      sRC;                            /* Range coder state                                                    */
-    SKP_Silk_range_coder_state      sRC_LBRR;                       /* Range coder state (for low bitrate redundancy)                       */
+    //SKP_Silk_range_coder_state      sRC;                            /* Range coder state                                                    */
+    //SKP_Silk_range_coder_state      sRC_LBRR;                       /* Range coder state (for low bitrate redundancy)                       */
 #if HIGH_PASS_INPUT
     SKP_int32                       In_HP_State[ 2 ];               /* High pass filter state                                               */
 #endif
@@ -277,7 +278,7 @@ typedef struct {
 /* Decoder state                */
 /********************************/
 typedef struct {
-    SKP_Silk_range_coder_state  sRC;                            /* Range coder state                                                    */
+    //SKP_Silk_range_coder_state  sRC;                            /* Range coder state                                                    */
     SKP_int32       prev_inv_gain_Q16;
     SKP_int32       sLTP_Q16[ 2 * MAX_FRAME_LENGTH ];
     SKP_int32       sLPC_Q14[ MAX_FRAME_LENGTH / MAX_NB_SUBFR + MAX_LPC_ORDER ];
diff --git a/src_common/SKP_Silk_tables.h b/src_common/SKP_Silk_tables.h
index 404820f5f9cc2656e62cefb7945d0e9f843a295f..126c7db9ca7e230ec3aebfa396118aebedee988c 100644
--- a/src_common/SKP_Silk_tables.h
+++ b/src_common/SKP_Silk_tables.h
@@ -148,8 +148,8 @@ extern const SKP_int16  SKP_Silk_Dec_A_HP_8[ DEC_HP_ORDER ];
 extern const SKP_int16  SKP_Silk_Dec_B_HP_8[ DEC_HP_ORDER + 1 ];                                    /*   3 */
 
 /* Table for frame termination indication */
-extern const SKP_uint16 SKP_Silk_FrameTermination_v4_CDF[ 6 ];
-extern const SKP_int    SKP_Silk_FrameTermination_v4_offset;
+extern const SKP_uint16 SKP_Silk_FrameTermination_CDF[ 6 ];
+extern const SKP_int    SKP_Silk_FrameTermination_offset;
 
 /* Table for random seed */
 extern const SKP_uint16 SKP_Silk_Seed_CDF[ 5 ];
diff --git a/src_common/SKP_Silk_tables_other.c b/src_common/SKP_Silk_tables_other.c
index b29c8dc967eb10b0f5ba4043c712f4785129e3b8..678a5e138d71bcc33733d55f5efd5726c9de0b1d 100644
--- a/src_common/SKP_Silk_tables_other.c
+++ b/src_common/SKP_Silk_tables_other.c
@@ -105,8 +105,8 @@ const SKP_uint16 SKP_Silk_NLSF_interpolation_factor_CDF[ 6 ] = {0,   3706,   870
 const SKP_int    SKP_Silk_NLSF_interpolation_factor_offset   = 4;
 
 /* Table for frame termination indication */
-const SKP_uint16 SKP_Silk_FrameTermination_v4_CDF[ 6 ] = {0,   13107,   26214,   39321,   52428,   65535};
-const SKP_int    SKP_Silk_FrameTermination_v4_offset   = 4;
+const SKP_uint16 SKP_Silk_FrameTermination_CDF[ 6 ] = {0,   13107,   26214,   39321,   52428,   65535};
+const SKP_int    SKP_Silk_FrameTermination_offset   = 4;
 
 /* Table for random seed */
 const SKP_uint16 SKP_Silk_Seed_CDF[ 5 ] = {0, 16384, 32768, 49152, 65535};
diff --git a/src_common/Silk_CommonFLP.vcproj b/src_common/Silk_CommonFLP.vcproj
index ca321633951a4eb38b3a0b545d9af6e01661b691..3a4bb39041bf9c49cefbe5ccc15dfb8d0f15bb2f 100644
--- a/src_common/Silk_CommonFLP.vcproj
+++ b/src_common/Silk_CommonFLP.vcproj
@@ -184,11 +184,11 @@
 				>
 			</File>
 			<File
-				RelativePath=".\SKP_Silk_decode_indices_v4.c"
+				RelativePath=".\SKP_Silk_decode_indices.c"
 				>
 			</File>
 			<File
-				RelativePath=".\SKP_Silk_decode_parameters_v4.c"
+				RelativePath=".\SKP_Silk_decode_parameters.c"
 				>
 			</File>
 			<File
@@ -208,7 +208,7 @@
 				>
 			</File>
 			<File
-				RelativePath=".\SKP_Silk_encode_parameters_v4.c"
+				RelativePath=".\SKP_Silk_encode_parameters.c"
 				>
 			</File>
 			<File
diff --git a/test/Dec_SDK.vcproj b/test/Dec_SDK.vcproj
index fecbc19f4c1a2bf54f65e3122f4ec33265170e79..d2c2b186744c7e33267b704e4466a6371d0ec7ca 100644
--- a/test/Dec_SDK.vcproj
+++ b/test/Dec_SDK.vcproj
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="Windows-1252"?>
 <VisualStudioProject
 	ProjectType="Visual C++"
-	Version="8,00"
+	Version="8.00"
 	Name="Dec"
 	ProjectGUID="{82685D7F-0589-42BD-877C-31A952D53A8E}"
 	RootNamespace="Test"
@@ -40,7 +40,7 @@
 			<Tool
 				Name="VCCLCompilerTool"
 				Optimization="0"
-				AdditionalIncludeDirectories="../interface;../src_SigProc_FIX"
+				AdditionalIncludeDirectories="../../../celt-0.8.0/libcelt;../interface;../src_SigProc_FIX"
 				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;COMPILE_SDK"
 				MinimalRebuild="true"
 				BasicRuntimeChecks="3"
@@ -121,7 +121,7 @@
 			/>
 			<Tool
 				Name="VCCLCompilerTool"
-				AdditionalIncludeDirectories="../interface;../src_SigProc_FIX"
+				AdditionalIncludeDirectories="../../../celt-0.8.0/libcelt;../interface;../src_SigProc_FIX"
 				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;COMPILE_SDK"
 				RuntimeLibrary="0"
 				FloatingPointModel="2"
diff --git a/test/Dec_SDK.vcproj.SKYPE-KOEN.koen.user b/test/Dec_SDK.vcproj.SKYPE-KOEN.koen.user
deleted file mode 100644
index 64fb3c3a4a7be1593e2cb37dec2e3539a471e50d..0000000000000000000000000000000000000000
--- a/test/Dec_SDK.vcproj.SKYPE-KOEN.koen.user
+++ /dev/null
@@ -1,65 +0,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioUserFile
-	ProjectType="Visual C++"
-	Version="8.00"
-	ShowAllFiles="false"
-	>
-	<Configurations>
-		<Configuration
-			Name="Debug|Win32"
-			>
-			<DebugSettings
-				Command="$(TargetPath)"
-				WorkingDirectory=""
-				CommandArguments=""
-				Attach="false"
-				DebuggerType="3"
-				Remote="1"
-				RemoteMachine="SKYPE-KOEN"
-				RemoteCommand=""
-				HttpUrl=""
-				PDBPath=""
-				SQLDebugging=""
-				Environment=""
-				EnvironmentMerge="true"
-				DebuggerFlavor=""
-				MPIRunCommand=""
-				MPIRunArguments=""
-				MPIRunWorkingDirectory=""
-				ApplicationCommand=""
-				ApplicationArguments=""
-				ShimCommand=""
-				MPIAcceptMode=""
-				MPIAcceptFilter=""
-			/>
-		</Configuration>
-		<Configuration
-			Name="Release|Win32"
-			>
-			<DebugSettings
-				Command="$(TargetPath)"
-				WorkingDirectory=""
-				CommandArguments=""
-				Attach="false"
-				DebuggerType="3"
-				Remote="1"
-				RemoteMachine="SKYPE-KOEN"
-				RemoteCommand=""
-				HttpUrl=""
-				PDBPath=""
-				SQLDebugging=""
-				Environment=""
-				EnvironmentMerge="true"
-				DebuggerFlavor=""
-				MPIRunCommand=""
-				MPIRunArguments=""
-				MPIRunWorkingDirectory=""
-				ApplicationCommand=""
-				ApplicationArguments=""
-				ShimCommand=""
-				MPIAcceptMode=""
-				MPIAcceptFilter=""
-			/>
-		</Configuration>
-	</Configurations>
-</VisualStudioUserFile>
diff --git a/test/Decoder.c b/test/Decoder.c
index 1e0cbe806bd780a3410341b9a4ea80f2a8596f76..d4c4cc0401c598a6bf2812c272951e94e64e9031 100644
--- a/test/Decoder.c
+++ b/test/Decoder.c
@@ -47,7 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #define MAX_FRAME_LENGTH        480
 #define MAX_FRAME_LENGTH_MS     20
 #define MAX_API_FS_KHZ          48
-#define MAX_LBRR_DELAY          2
+#define MAX_LBRR_DELAY          0
 
 #ifdef _SYSTEM_IS_BIG_ENDIAN
 /* Function to convert a little endian int16 to a */
@@ -108,6 +108,8 @@ int main( int argc, char* argv[] )
     float     loss_prob;
     SKP_int32 frames, lost, quiet;
     SKP_SILK_SDK_DecControlStruct DecControl;
+    ec_byte_buffer range_dec_celt_buf;
+    ec_dec         range_dec_celt_state;
 
     if( argc < 3 ) {
         print_usage( argv );
@@ -217,6 +219,10 @@ int main( int argc, char* argv[] )
             break;
         }
 
+        /* Initialize range decoder state */
+        ec_byte_writeinit_buffer( &range_dec_celt_buf, payloadEnd, nBytes );
+        ec_dec_init( &range_dec_celt_state, &range_dec_celt_buf );
+
         /* Simulate losses */
         if( ( (float)rand() / (float)RAND_MAX >= loss_prob / 100 ) && counter > 0 ) {
             nBytesPerPacket[ MAX_LBRR_DELAY ] = nBytes;
@@ -234,7 +240,7 @@ int main( int argc, char* argv[] )
             for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
                 if( nBytesPerPacket[ i + 1 ] > 0 ) {
                     starttime = GetHighResolutionTime();
-                    SKP_Silk_SDK_search_for_LBRR( payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC );
+                    //SKP_Silk_SDK_search_for_LBRR( payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC );
                     tottime += GetHighResolutionTime() - starttime;
                     if( nBytesFEC > 0 ) {
                         payloadToDec = FECpayload;
@@ -261,7 +267,7 @@ int main( int argc, char* argv[] )
             do {
                 /* Decode 20 ms */
                 starttime = GetHighResolutionTime();
-                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, payloadToDec, nBytes, outPtr, &len );
+                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, &range_dec_celt_state, nBytes, outPtr, &len );
                 tottime += GetHighResolutionTime() - starttime;
                 if( ret ) {
                     printf( "\nSKP_Silk_SDK_Decode returned %d", ret );
@@ -287,7 +293,7 @@ int main( int argc, char* argv[] )
             for( i = 0; i < DecControl.framesPerPacket; i++ ) {
                 /* Generate 20 ms */
                 starttime = GetHighResolutionTime();
-                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, payloadToDec, nBytes, outPtr, &len );
+                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, &range_dec_celt_state, nBytes, outPtr, &len );
                 tottime += GetHighResolutionTime() - starttime;
                 if( ret ) {
                     printf( "\nSKP_Silk_Decode returned %d", ret );
@@ -335,7 +341,7 @@ int main( int argc, char* argv[] )
             for( i = 0; i < MAX_LBRR_DELAY; i++ ) {
                 if( nBytesPerPacket[ i + 1 ] > 0 ) {
                     starttime = GetHighResolutionTime();
-                    SKP_Silk_SDK_search_for_LBRR( payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC );
+                    //SKP_Silk_SDK_search_for_LBRR( payloadPtr, nBytesPerPacket[ i + 1 ], i + 1, FECpayload, &nBytesFEC );
                     tottime += GetHighResolutionTime() - starttime;
                     if( nBytesFEC > 0 ) {
                         payloadToDec = FECpayload;
@@ -362,7 +368,7 @@ int main( int argc, char* argv[] )
             do {
                 /* Decode 20 ms */
                 starttime = GetHighResolutionTime();
-                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, payloadToDec, nBytes, outPtr, &len );
+                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 0, &range_dec_celt_state, nBytes, outPtr, &len );
                 tottime += GetHighResolutionTime() - starttime;
                 if( ret ) {
                     printf( "\nSKP_Silk_SDK_Decode returned %d", ret );
@@ -385,7 +391,7 @@ int main( int argc, char* argv[] )
             /* Generate 20 ms */
             for( i = 0; i < DecControl.framesPerPacket; i++ ) {
                 starttime = GetHighResolutionTime();
-                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, payloadToDec, nBytes, outPtr, &len );
+                ret = SKP_Silk_SDK_Decode( psDec, &DecControl, 1, &range_dec_celt_state, nBytes, outPtr, &len );
                 tottime += GetHighResolutionTime() - starttime;
                 if( ret ) {
                     printf( "\nSKP_Silk_Decode returned %d", ret );
diff --git a/test/Enc_SDK.vcproj b/test/Enc_SDK.vcproj
index 8d877f8fd0882cd839fc9a096151f193d64d94aa..b3269b9e540f2fbb296d7de4022c790d4b90f117 100644
--- a/test/Enc_SDK.vcproj
+++ b/test/Enc_SDK.vcproj
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="Windows-1252"?>
 <VisualStudioProject
 	ProjectType="Visual C++"
-	Version="8,00"
+	Version="8.00"
 	Name="Enc"
 	ProjectGUID="{6D97A8EF-5724-4D85-8BF4-C583714BBA78}"
 	RootNamespace="Enc"
@@ -40,7 +40,7 @@
 			<Tool
 				Name="VCCLCompilerTool"
 				Optimization="0"
-				AdditionalIncludeDirectories="../interface;../src_SigProc_FIX"
+				AdditionalIncludeDirectories="../../../celt-0.8.0/libcelt;../interface;../src_SigProc_FIX"
 				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
 				MinimalRebuild="true"
 				BasicRuntimeChecks="3"
@@ -121,7 +121,7 @@
 			/>
 			<Tool
 				Name="VCCLCompilerTool"
-				AdditionalIncludeDirectories="../interface;../src_SigProc_FIX"
+				AdditionalIncludeDirectories="../../../celt-0.8.0/libcelt;../interface;../src_SigProc_FIX"
 				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
 				RuntimeLibrary="0"
 				FloatingPointModel="2"
diff --git a/test/Enc_SDK.vcproj.SKYPE-KOEN.koen.user b/test/Enc_SDK.vcproj.SKYPE-KOEN.koen.user
deleted file mode 100644
index 64fb3c3a4a7be1593e2cb37dec2e3539a471e50d..0000000000000000000000000000000000000000
--- a/test/Enc_SDK.vcproj.SKYPE-KOEN.koen.user
+++ /dev/null
@@ -1,65 +0,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioUserFile
-	ProjectType="Visual C++"
-	Version="8.00"
-	ShowAllFiles="false"
-	>
-	<Configurations>
-		<Configuration
-			Name="Debug|Win32"
-			>
-			<DebugSettings
-				Command="$(TargetPath)"
-				WorkingDirectory=""
-				CommandArguments=""
-				Attach="false"
-				DebuggerType="3"
-				Remote="1"
-				RemoteMachine="SKYPE-KOEN"
-				RemoteCommand=""
-				HttpUrl=""
-				PDBPath=""
-				SQLDebugging=""
-				Environment=""
-				EnvironmentMerge="true"
-				DebuggerFlavor=""
-				MPIRunCommand=""
-				MPIRunArguments=""
-				MPIRunWorkingDirectory=""
-				ApplicationCommand=""
-				ApplicationArguments=""
-				ShimCommand=""
-				MPIAcceptMode=""
-				MPIAcceptFilter=""
-			/>
-		</Configuration>
-		<Configuration
-			Name="Release|Win32"
-			>
-			<DebugSettings
-				Command="$(TargetPath)"
-				WorkingDirectory=""
-				CommandArguments=""
-				Attach="false"
-				DebuggerType="3"
-				Remote="1"
-				RemoteMachine="SKYPE-KOEN"
-				RemoteCommand=""
-				HttpUrl=""
-				PDBPath=""
-				SQLDebugging=""
-				Environment=""
-				EnvironmentMerge="true"
-				DebuggerFlavor=""
-				MPIRunCommand=""
-				MPIRunArguments=""
-				MPIRunWorkingDirectory=""
-				ApplicationCommand=""
-				ApplicationArguments=""
-				ShimCommand=""
-				MPIAcceptMode=""
-				MPIAcceptFilter=""
-			/>
-		</Configuration>
-	</Configurations>
-</VisualStudioUserFile>
diff --git a/test/Encoder.c b/test/Encoder.c
index 6a0dedaf2d198d04a5b71503e7ea2659458fed1c..fe675c5712cb71c65f88c5f1cd63cd0563274232 100644
--- a/test/Encoder.c
+++ b/test/Encoder.c
@@ -99,7 +99,6 @@ int main( int argc, char* argv[] )
     SKP_int32 k, args, totPackets, totActPackets, ret;
     SKP_int16 nBytes;
     double    sumBytes, sumActBytes, avg_rate, act_rate, nrg;
-    SKP_uint8 payload[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES ];
     SKP_int16 in[ MAX_FRAME_LENGTH_MS * MAX_API_FS_KHZ * MAX_INPUT_FRAMES ];
     char      speechInFileName[ 150 ], bitOutFileName[ 150 ];
     FILE      *bitOutFile, *speechInFile;
@@ -111,6 +110,9 @@ int main( int argc, char* argv[] )
 #ifdef _SYSTEM_IS_BIG_ENDIAN
     SKP_int16 nBytes_LE;
 #endif
+    SKP_uint8      range_buf[ MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES ];
+    ec_byte_buffer range_enc_celt_buf;
+    ec_enc         range_enc_celt_state;
 
     /* default settings */
     SKP_int32 API_fs_Hz = 24000;
@@ -121,6 +123,7 @@ int main( int argc, char* argv[] )
     SKP_int32 packetLoss_perc = 0, complexity_mode = 2, smplsSinceLastPacket;
     SKP_int32 INBandFEC_enabled = 0, DTX_enabled = 0, quiet = 0;
     SKP_SILK_SDK_EncControlStruct encControl; // Struct for input to encoder
+
         
     if( argc < 3 ) {
         print_usage( argv );
@@ -235,8 +238,12 @@ int main( int argc, char* argv[] )
     smplsSinceLastPacket = 0;
     sumBytes             = 0.0;
     sumActBytes          = 0.0;
-    
+
     while( 1 ) {
+        /* Init range coder */
+        ec_byte_writeinit_buffer( &range_enc_celt_buf, range_buf, MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES );
+        ec_enc_init( &range_enc_celt_state, &range_enc_celt_buf );
+        
         /* Read input from file */
         counter = fread( in, sizeof( SKP_int16 ), ( frameSizeReadFromFile_ms * API_fs_Hz ) / 1000, speechInFile );
 #ifdef _SYSTEM_IS_BIG_ENDIAN
@@ -251,7 +258,7 @@ int main( int argc, char* argv[] )
 
         starttime = GetHighResolutionTime();
         /* Silk Encoder */
-        ret = SKP_Silk_SDK_Encode( psEnc, &encControl, in, (SKP_int16)counter, payload, &nBytes );
+        ret = SKP_Silk_SDK_Encode( psEnc, &encControl, in, (SKP_int16)counter, &range_enc_celt_state, &nBytes );
         if( ret ) {
             printf( "\nSKP_Silk_Encode returned %d", ret );
             break;
@@ -294,7 +301,7 @@ int main( int argc, char* argv[] )
 #endif
 
             /* Write payload */
-            fwrite( payload, sizeof( SKP_uint8 ), nBytes, bitOutFile );
+            fwrite( range_buf, sizeof( SKP_uint8 ), nBytes, bitOutFile );
         
             if( !quiet ) {
                 fprintf( stderr, "\rPackets encoded:              %d", totPackets );
diff --git a/test/SignalCompare.vcproj.SKYPE-KOEN.koen.user b/test/SignalCompare.vcproj.SKYPE-KOEN.koen.user
deleted file mode 100644
index 64fb3c3a4a7be1593e2cb37dec2e3539a471e50d..0000000000000000000000000000000000000000
--- a/test/SignalCompare.vcproj.SKYPE-KOEN.koen.user
+++ /dev/null
@@ -1,65 +0,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioUserFile
-	ProjectType="Visual C++"
-	Version="8.00"
-	ShowAllFiles="false"
-	>
-	<Configurations>
-		<Configuration
-			Name="Debug|Win32"
-			>
-			<DebugSettings
-				Command="$(TargetPath)"
-				WorkingDirectory=""
-				CommandArguments=""
-				Attach="false"
-				DebuggerType="3"
-				Remote="1"
-				RemoteMachine="SKYPE-KOEN"
-				RemoteCommand=""
-				HttpUrl=""
-				PDBPath=""
-				SQLDebugging=""
-				Environment=""
-				EnvironmentMerge="true"
-				DebuggerFlavor=""
-				MPIRunCommand=""
-				MPIRunArguments=""
-				MPIRunWorkingDirectory=""
-				ApplicationCommand=""
-				ApplicationArguments=""
-				ShimCommand=""
-				MPIAcceptMode=""
-				MPIAcceptFilter=""
-			/>
-		</Configuration>
-		<Configuration
-			Name="Release|Win32"
-			>
-			<DebugSettings
-				Command="$(TargetPath)"
-				WorkingDirectory=""
-				CommandArguments=""
-				Attach="false"
-				DebuggerType="3"
-				Remote="1"
-				RemoteMachine="SKYPE-KOEN"
-				RemoteCommand=""
-				HttpUrl=""
-				PDBPath=""
-				SQLDebugging=""
-				Environment=""
-				EnvironmentMerge="true"
-				DebuggerFlavor=""
-				MPIRunCommand=""
-				MPIRunArguments=""
-				MPIRunWorkingDirectory=""
-				ApplicationCommand=""
-				ApplicationArguments=""
-				ShimCommand=""
-				MPIAcceptMode=""
-				MPIAcceptFilter=""
-			/>
-		</Configuration>
-	</Configurations>
-</VisualStudioUserFile>