convert X509Name to a type that can be instantiated
diff --git a/src/crypto/crypto.c b/src/crypto/crypto.c
index b959909..43c8c90 100644
--- a/src/crypto/crypto.c
+++ b/src/crypto/crypto.c
@@ -515,25 +515,6 @@
 }
 
 
-static char crypto_X509Name_doc[] = "\n\
-The factory function inserted in the module dictionary as a copy\n\
-constructor for X509Name objects.\n\
-\n\
-@param name: An X509Name object to copy\n\
-@return: The X509Name object\n\
-";
-
-static PyObject *
-crypto_X509Name(PyObject *spam, PyObject *args)
-{
-    crypto_X509NameObj *name;
-
-    if (!PyArg_ParseTuple(args, "O!:X509Name", &crypto_X509Name_Type, &name))
-        return NULL;
-
-    return (PyObject *)crypto_X509Name_New(X509_NAME_dup(name->x509_name), 1);
-}
-
 static char crypto_X509Req_doc[] = "\n\
 The factory function inserted in the module dictionary to create X509Req\n\
 objects\n\
@@ -639,7 +620,6 @@
     { "load_pkcs7_data", (PyCFunction)crypto_load_pkcs7_data, METH_VARARGS, crypto_load_pkcs7_data_doc },
     { "load_pkcs12", (PyCFunction)crypto_load_pkcs12, METH_VARARGS, crypto_load_pkcs12_doc },
     /* Factory functions */
-    { "X509Name",(PyCFunction)crypto_X509Name,METH_VARARGS, crypto_X509Name_doc },
     { "X509Req", (PyCFunction)crypto_X509Req, METH_VARARGS, crypto_X509Req_doc },
     { "X509Extension", (PyCFunction)crypto_X509Extension, METH_VARARGS, crypto_X509Extension_doc },
     { "NetscapeSPKI", (PyCFunction)crypto_NetscapeSPKI, METH_VARARGS, crypto_NetscapeSPKI_doc },
@@ -766,7 +746,7 @@
 #endif
     if (!init_crypto_x509(module))
         goto error;
-    if (!init_crypto_x509name(dict))
+    if (!init_crypto_x509name(module))
         goto error;
     if (!init_crypto_x509store(dict))
         goto error;
diff --git a/src/crypto/x509name.c b/src/crypto/x509name.c
index 19c3fe0..5d49430 100644
--- a/src/crypto/x509name.c
+++ b/src/crypto/x509name.c
@@ -41,6 +41,29 @@
     return self;
 }
 
+
+static char crypto_X509Name_doc[] = "\n\
+X509Name(name) -> New X509Name object\n\
+\n\
+Create a new X509Name, copying the given X509Name instance.\n\
+\n\
+@param name: An X509Name object to copy\n\
+@return: The X509Name object\n\
+";
+
+static PyObject *
+crypto_X509Name_new(PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
+{
+    crypto_X509NameObj *name;
+
+    if (!PyArg_ParseTuple(args, "O!:X509Name", &crypto_X509Name_Type, &name)) {
+        return NULL;
+    }
+
+    return (PyObject *)crypto_X509Name_New(X509_NAME_dup(name->x509_name), 1);
+}
+
+
 /*
  * Return a name string given a X509_NAME object and a name identifier. Used
  * by the getattr function.
@@ -412,22 +435,46 @@
     NULL, /* setattro */
     NULL, /* as_buffer */
     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
-    NULL, /* tp_doc */
+    crypto_X509Name_doc, /* tp_doc */
     (traverseproc)crypto_X509Name_traverse, /* tp_traverse */
     (inquiry)crypto_X509Name_clear, /* tp_clear */
+    NULL, /* tp_richcompare */
+    0, /* tp_weaklistoffset */
+    NULL, /* tp_iter */
+    NULL, /* tp_iternext */
+    crypto_X509Name_methods, /* tp_methods */
+    NULL, /* tp_members */
+    NULL, /* tp_getset */
+    NULL, /* tp_base */
+    NULL, /* tp_dict */
+    NULL, /* tp_descr_get */
+    NULL, /* tp_descr_set */
+    0, /* tp_dictoffset */
+    NULL, /* tp_init */
+    NULL, /* tp_alloc */
+    crypto_X509Name_new, /* tp_new */
 };
 
 /*
  * Initialize the X509Name part of the crypto module
  *
- * Arguments: dict - The crypto module dictionary
+ * Arguments: module - The crypto module
  * Returns:   None
  */
 int
-init_crypto_x509name(PyObject *dict)
+init_crypto_x509name(PyObject *module)
 {
-    crypto_X509Name_Type.ob_type = &PyType_Type;
-    Py_INCREF(&crypto_X509Name_Type);
-    PyDict_SetItemString(dict, "X509NameType", (PyObject *)&crypto_X509Name_Type);
+    if (PyType_Ready(&crypto_X509Name_Type) < 0) {
+        return 0;
+    }
+
+    if (PyModule_AddObject(module, "X509Name", (PyObject *)&crypto_X509Name_Type) != 0) {
+        return 0;
+    }
+
+    if (PyModule_AddObject(module, "X509NameType", (PyObject *)&crypto_X509Name_Type) != 0) {
+        return 0;
+    }
+
     return 1;
 }