             else { return nil }
         
         let pointer = UnsafeMutablePointer<bson_oid_t>()
+        defer { pointer.dealloc(1) }
         
         bson_oid_init_from_string_unsafe(pointer, rawValue)
         
-        self = pointer.memory
+        self.byteValue = pointer.memory.bytes
     }
     
     public var rawValue: String {
         
-        var copy = self
+        let oidPointer = UnsafeMutablePointer<bson_oid_t>.alloc(1)
+        defer { oidPointer.dealloc(1) }
+        
+        oidPointer.memory.bytes = self.byteValue
         
         let stringPointer = UnsafeMutablePointer<CChar>.alloc(25)
         defer { stringPointer.dealloc(25) }
         
-        bson_oid_to_string(&copy, stringPointer)
+        bson_oid_to_string(oidPointer, stringPointer)
         
         return String.fromCString(stringPointer)!
     }


public func ==(lhs: BSON.ObjectID, rhs: BSON.ObjectID) -> Bool {
    
    var oid1 = lhs
    
    var oid2 = rhs
    
    return bson_oid_equal(&oid1, &oid2)
}





public extension BSON {
    
    public struct ObjectID: ByteValue {
        
        public typealias ByteValueType = (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)
        
        public private(set) var byteValue: ByteValueType
    }
}

