                     if rangeDecoder.decode(bitWithProb: &probabilities[241 + (state << LZMAConstants.numPosBitsMax) + posState]) == 0 {
                         // SHORT REP MATCH CASE
                         state = state < 7 ? 9 : 11
-                        let byte = out[rep0 + 1 <= dictEnd ? dictEnd - rep0 - 1 : dictionarySize - rep0 - 1 + dictEnd]
-                        out.append(byte)
+                        let byte = self.byte(at: rep0 + 1)
                         uncompressedSize -= 1
-                        dictEnd += 1
-                        if dictEnd - dictStart == dictionarySize {
-                            dictStart += 1
-                        }
+                        self.put(byte)
                         continue
                     }
                 } else { // REP MATCH CASE

            len += LZMAConstants.matchMinLen
            if uncompressedSize > -1 && uncompressedSize < len { throw LZMAError.RepeatWillExceed }
            for _ in 0..<len {
                let byte = out[rep0 + 1 <= dictEnd ? dictEnd - rep0 - 1 : dictionarySize - rep0 - 1 + dictEnd]
                out.append(byte)
                uncompressedSize -= 1
                dictEnd += 1
                if dictEnd - dictStart == dictionarySize {
                    dictStart += 1
                }
            }
        }
    }
    
}

        self.lenDecoder = LZMALenDecoder(&self.pointerData)
        self.repLenDecoder = LZMALenDecoder(&self.pointerData)
    }

    // MARK: LZMA2 related functions.

    private func resetProperties() throws {
        var properties = pointerData.alignedByte()
