                         if rightChildIndex < self.leafCount {
                             switch self.tree[rightChildIndex] {
                             case .leaf(let rightSymbol):
-                                replacementArray.append(rightSymbol)
+                                replacementArray.insert(rightSymbol)
                             case .branch(let rightArray):
                                 for rightChild in rightArray {
-                                    replacementArray.append(rightChild)
+                                    replacementArray.insert(rightChild)
                                 }
                             }
                         }

                switch self.tree[treeIndex] {
                case .leaf(let symbol):
                    if symbol == -1 {
                        var replacementArray = [Int]()

                        let leftChildIndex = 2 * treeIndex + 1
                        if leftChildIndex < self.leafCount {
                            switch self.tree[leftChildIndex] {
                            case .leaf(let leftSymbol):
                                replacementArray.append(leftSymbol)
                            case .branch(let leftArray):
                                for leftChild in leftArray {
                                    replacementArray.append(leftChild)
                                }
                            }
                        }


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

    private var pointerData: DataWithPointer
