         let length = getLengthOfElement(withDataPosition: meta.dataPosition, type: meta.type)
         
         storage.removeSubrange(meta.elementTypePosition..<meta.dataPosition + length)
+        updateDocumentHeader()
         
         return val
     }

            
            storage.removeSubrange(position..<position+length)
            storage.insert(contentsOf: newValue.value.bytes, at: position)
        }
    }
    

    
    public init() {
        // the empty document is 5 bytes long.
        storage = [5,0,0,0,0]
    }
    
    // MARK: - Initialization from Swift Types & Literals
