convert X509Req to a type that can be instantiated
diff --git a/src/crypto/crypto.c b/src/crypto/crypto.c
index 43c8c90..a933dce 100644
--- a/src/crypto/crypto.c
+++ b/src/crypto/crypto.c
@@ -515,23 +515,6 @@
 }
 
 
-static char crypto_X509Req_doc[] = "\n\
-The factory function inserted in the module dictionary to create X509Req\n\
-objects\n\
-\n\
-@returns: The X509Req object\n\
-";
-
-static PyObject *
-crypto_X509Req(PyObject *spam, PyObject *args)
-{
-    if (!PyArg_ParseTuple(args, ":X509Req"))
-        return NULL;
-
-    return (PyObject *)crypto_X509Req_New(X509_REQ_new(), 1);
-}
-
-
 static char crypto_X509Extension_doc[] = "\n\
 The factory function inserted in the module dictionary to create\n\
 X509Extension objects.\n\
@@ -620,7 +603,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 */
-    { "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 },
     { "X509_verify_cert_error_string", (PyCFunction)crypto_X509_verify_cert_error_string, METH_VARARGS, crypto_X509_verify_cert_error_string_doc },
@@ -750,7 +732,7 @@
         goto error;
     if (!init_crypto_x509store(dict))
         goto error;
-    if (!init_crypto_x509req(dict))
+    if (!init_crypto_x509req(module))
         goto error;
     if (!init_crypto_pkey(module))
         goto error;
diff --git a/src/crypto/x509req.c b/src/crypto/x509req.c
index 93865ce..a1325e9 100644
--- a/src/crypto/x509req.c
+++ b/src/crypto/x509req.c
@@ -319,6 +319,25 @@
     return self;
 }
 
+
+static char crypto_X509Req_doc[] = "\n\
+X509Req() -> X509Req instance\n\
+\n\
+Create a new X509Req object.\n\
+\n\
+@return: The X509Req object\n\
+";
+
+static PyObject *
+crypto_X509Req_new(PyTypeObject *subtype, PyObject *args, PyObject *kwargs) {
+    if (!PyArg_ParseTuple(args, ":X509Req")) {
+        return NULL;
+    }
+
+    return (PyObject *)crypto_X509Req_New(X509_REQ_new(), 1);
+}
+
+
 /*
  * Deallocate the memory used by the X509Req object
  *
@@ -359,20 +378,60 @@
     (destructor)crypto_X509Req_dealloc,
     NULL, /* print */
     (getattrfunc)crypto_X509Req_getattr,
+    NULL, /* setattr */
+    NULL, /* compare */
+    NULL, /* repr */
+    NULL, /* as_number */
+    NULL, /* as_sequence */
+    NULL, /* as_mapping */
+    NULL, /* hash */
+    NULL, /* call */
+    NULL, /* str */
+    NULL, /* getattro */
+    NULL, /* setattro */
+    NULL, /* as_buffer */
+    Py_TPFLAGS_DEFAULT,
+    crypto_X509Req_doc, /* doc */
+    NULL, /* traverse */
+    NULL, /* clear */
+    NULL, /* tp_richcompare */
+    0, /* tp_weaklistoffset */
+    NULL, /* tp_iter */
+    NULL, /* tp_iternext */
+    crypto_X509Req_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_X509Req_new, /* tp_new */
 };
 
 
 /*
  * Initialize the X509Req part of the crypto module
  *
- * Arguments: dict - The crypto module dictionary
+ * Arguments: module - The crypto module
  * Returns:   None
  */
 int
-init_crypto_x509req(PyObject *dict)
+init_crypto_x509req(PyObject *module)
 {
-    crypto_X509Req_Type.ob_type = &PyType_Type;
-    Py_INCREF(&crypto_X509Req_Type);
-    PyDict_SetItemString(dict, "X509ReqType", (PyObject *)&crypto_X509Req_Type);
+    if (PyType_Ready(&crypto_X509Req_Type) < 0) {
+        return 0;
+    }
+
+    if (PyModule_AddObject(module, "X509Req", (PyObject *)&crypto_X509Req_Type) != 0) {
+        return 0;
+    }
+
+    if (PyModule_AddObject(module, "X509ReqType", (PyObject *)&crypto_X509Req_Type) != 0) {
+        return 0;
+    }
+
     return 1;
 }