             // TODO: Add limitation for dictionary size.
         }
 
+        // For last two bytes there certainly will be no match.
+        // Moreover, `threeByteCrc` cannot be computed, so we need to put them in as `.byte`s.
+        while inputIndex < rawBytes.count {
+            let byte = rawBytes[inputIndex]
+            buffer.append(BLDCode.byte(byte))
+            stats[byte.toInt()] += 1
+            inputIndex += 1
+        }
+
+        // End of block symbol (256) should also be counted.
         stats[256] += 1
 
         return (buffer, stats)

    public static func compress(data: Data) throws -> Data {
        let bytes = data.toArray(type: UInt8.self)

        if bytes.count < 3 {
            return Data(bytes: Deflate.createUncompressedBlock(bytes))
        }

        let bldCodes = Deflate.lengthEncode(bytes)

        // Let's count possible sizes according to statistics.


        var stats = Array(repeating: 0, count: 316)

        // Last two bytes of input will be considered separately.
        // This also allows to use length encoding for arrays with size less than 3.
        while inputIndex < rawBytes.count - 2 {
            let byte = rawBytes[inputIndex]

            let threeByteCrc = CheckSums.crc32([rawBytes[inputIndex],
                                                rawBytes[inputIndex + 1],
