convert X509 to a type that can be instantiated
diff --git a/src/crypto/crypto.c b/src/crypto/crypto.c
index 2024077..b959909 100644
--- a/src/crypto/crypto.c
+++ b/src/crypto/crypto.c
@@ -515,22 +515,6 @@
 }
 
 
-static char crypto_X509_doc[] = "\n\
-The factory function inserted in the module dictionary to create X509\n\
-objects\n\
-\n\
-@returns: The X509 object\n\
-";
-
-static PyObject *
-crypto_X509(PyObject *spam, PyObject *args)
-{
-    if (!PyArg_ParseTuple(args, ":X509"))
-        return NULL;
-
-    return (PyObject *)crypto_X509_New(X509_new(), 1);
-}
-
 static char crypto_X509Name_doc[] = "\n\
 The factory function inserted in the module dictionary as a copy\n\
 constructor for X509Name objects.\n\
@@ -655,7 +639,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 */
-    { "X509",    (PyCFunction)crypto_X509,    METH_VARARGS, crypto_X509_doc },
     { "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 },
diff --git a/src/crypto/x509.c b/src/crypto/x509.c
index 5c5fafb..119c048 100644
--- a/src/crypto/x509.c
+++ b/src/crypto/x509.c
@@ -747,6 +747,26 @@
     return self;
 }
 
+
+static char crypto_X509_doc[] = "\n\
+X509() -> X509 instance\n\
+\n\
+Create a new X509 object.\n\
+\n\
+@returns: The X509 object\n\
+";
+
+static PyObject *
+crypto_X509_new(PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
+{
+    if (!PyArg_ParseTuple(args, ":X509")) {
+        return NULL;
+    }
+
+    return (PyObject *)crypto_X509_New(X509_new(), 1);
+}
+
+
 /*
  * Deallocate the memory used by the X509 object
  *
@@ -786,20 +806,60 @@
     (destructor)crypto_X509_dealloc,
     NULL, /* print */
     (getattrfunc)crypto_X509_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_X509_doc, /* doc */
+    NULL, /* traverse */
+    NULL, /* clear */
+    NULL, /* tp_richcompare */
+    0, /* tp_weaklistoffset */
+    NULL, /* tp_iter */
+    NULL, /* tp_iternext */
+    crypto_X509_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_X509_new, /* tp_new */
 };
 
 /*
  * Initialize the X509 part of the crypto sub module
  *
- * Arguments: dict - The crypto module dictionary
+ * Arguments: module - The crypto module
  * Returns:   None
  */
 int
-init_crypto_x509(PyObject *dict)
+init_crypto_x509(PyObject *module)
 {
-    crypto_X509_Type.ob_type = &PyType_Type;
-    Py_INCREF(&crypto_X509_Type);
-    PyDict_SetItemString(dict, "X509Type", (PyObject *)&crypto_X509_Type);
+    if (PyType_Ready(&crypto_X509_Type) < 0) {
+        return 0;
+    }
+
+    if (PyModule_AddObject(module, "X509", (PyObject *)&crypto_X509_Type) != 0) {
+        return 0;
+    }
+
+    if (PyModule_AddObject(module, "X509Type", (PyObject *)&crypto_X509_Type) != 0) {
+        return 0;
+    }
+
     return 1;
 }