                 index = bit == 0 ? 2 * index + 1 : 2 * index + 2
                 treeCode >>= 1
             }
-            self.tree[index] = .leaf(length[0])
-        }
-
-        if coding {
-            for treeIndex in stride(from: self.leafCount - 1, through: 0, by: -1) {
-                switch self.tree[treeIndex] {
-                case .leaf(let symbol):
-                    if symbol == -1 {
-                        var replacementArray = Set<Int>()
-
-                        let leftChildIndex = 2 * treeIndex + 1
-                        if leftChildIndex < self.leafCount {
-                            switch self.tree[leftChildIndex] {
-                            case .leaf(let leftSymbol):
-                                replacementArray.insert(leftSymbol)
-                            case .branch(let leftArray):
-                                for leftChild in leftArray {
-                                    replacementArray.insert(leftChild)
-                                }
-                            }
-                        }
-
-                        let rightChildIndex = 2 * treeIndex + 2
-                        if rightChildIndex < self.leafCount {
-                            switch self.tree[rightChildIndex] {
-                            case .leaf(let rightSymbol):
-                                replacementArray.insert(rightSymbol)
-                            case .branch(let rightArray):
-                                for rightChild in rightArray {
-                                    replacementArray.insert(rightChild)
-                                }
-                            }
-                        }
-
-                        self.tree[treeIndex] = .branch(replacementArray)
-                    }
-                default:
-                    continue
-                }
-            }
+            self.tree[index] = length[0]
         }
     }
 


class HuffmanTree {

    private enum HTNode {
        case leaf(Int)
        case branch(Set<Int>)
    }

    private var pointerData: DataWithPointer

    private var tree: [HTNode]
    private let leafCount: Int

    private let coding: Bool
    /// Special array for coding part. Index in array = symbol, value in array = index in tree.
    private var codingIndices: [[Int]]

    init(bootstrap: [[Int]], _ pointerData: inout DataWithPointer, _ coding: Bool = false) {
        self.coding = coding

            guard index < self.leafCount else {
                return -1
            }
            if self.tree[index] > -1 {
                return self.tree[index]
            }
        }
    }
