         return bitWriter.buffer
     }
 
-    private struct LengthDistance {
-
-        let length: Int
-        let lengthSymbol: Int
-        let lengthExtraBits: Int
-        let lengthExtraBitsCount: Int
-
-        let distance: Int
-        let distanceSymbol: Int
-        let distanceExtraBits: Int
-        let distanceExtraBitsCount: Int
-
-        init(_ length: Int, _ distance: Int) {
-            self.length = length
-            let lengthSymbol = Constants.lengthCode[length - 3]
-            self.lengthSymbol = lengthSymbol
-            self.lengthExtraBits = length - Constants.lengthBase[lengthSymbol - 257]
-            self.lengthExtraBitsCount = (257 <= lengthSymbol && lengthSymbol <= 260) || lengthSymbol == 285 ?
-                0 : (((lengthSymbol - 257) >> 2) - 1)
-
-            self.distance = distance
-            let distanceSymbol = ((Constants.distanceBase.index { $0 > distance }) ?? 30) - 1
-            self.distanceSymbol = distanceSymbol
-            self.distanceExtraBits = distance - Constants.distanceBase[distanceSymbol]
-            self.distanceExtraBitsCount = distanceSymbol == 0 || distanceSymbol == 1 ? 0 : ((distanceSymbol >> 1) - 1)
-        }
-
-    }
-
     private enum BLDCode {
         case byte(UInt8)
-        case lengthDistance(LengthDistance)
+        case lengthDistance(UInt16, UInt16)
     }
 
     private static func lengthEncode(_ rawBytes: [UInt8]) -> (codes: [BLDCode], stats: [Int]) {

            switch code {
            case .byte(let byte):
                try mainLiterals.code(symbol: byte.toInt(), &bitWriter, DeflateError.symbolNotFound)
            case .lengthDistance(let ld):
                try mainLiterals.code(symbol: ld.lengthSymbol, &bitWriter, DeflateError.symbolNotFound)
                bitWriter.write(number: ld.lengthExtraBits, bitsCount: ld.lengthExtraBitsCount)

                try mainDistances.code(symbol: ld.distanceSymbol, &bitWriter, DeflateError.symbolNotFound)
                bitWriter.write(number: ld.distanceExtraBits, bitsCount: ld.distanceExtraBitsCount)
            }
        }


                            repeatIndex = matchStartIndex + 1
                        }
                    }
                    buffer.append(BLDCode.lengthDistance(UInt16(truncatingBitPattern: matchLength), UInt16(truncatingBitPattern: distance)))
                    stats[Constants.lengthCode[matchLength - 3]] += 1 // Length symbol.
                    stats[286 + ((Constants.distanceBase.index { $0 > distance }) ?? 30) - 1] += 1 // Distance symbol.
                    inputIndex += matchLength
                } else {
                    buffer.append(BLDCode.byte(byte))
