Really really really get PyOpenSSL_LongToHex right now
diff --git a/OpenSSL/crypto/x509.c b/OpenSSL/crypto/x509.c
index 6156da0..1dc6506 100644
--- a/OpenSSL/crypto/x509.c
+++ b/OpenSSL/crypto/x509.c
@@ -95,7 +95,7 @@
     PyObject *hex = NULL;
     ASN1_INTEGER *asn1_i = NULL;
     BIGNUM *bignum = NULL;
-    char *hexbytes;
+    char *hexstr;
 
     if (!PyArg_ParseTuple(args, "O:set_serial_number", &serial)) {
         return NULL;
@@ -111,17 +111,25 @@
         goto err;
     }
 
+#ifdef PY3
+    {
+        PyObject *hexbytes = PyUnicode_AsASCIIString(hex);
+        Py_DECREF(hex);
+        hex = hexbytes;
+    }
+#endif
+
     /**
      * BN_hex2bn stores the result in &bignum.  Unless it doesn't feel like
      * it.  If bignum is still NULL after this call, then the return value
      * is actually the result.  I hope.  -exarkun
      */
-    hexbytes = PyBytes_AsString(hex);
-    if (hexbytes[2] == 'x') {
+    hexstr = PyBytes_AsString(hex);
+    if (hexstr[2] == 'x') {
         /* +2 to skip the "0x" */
-        hexbytes += 2;
+        hexstr += 2;
     }
-    small_serial = BN_hex2bn(&bignum, hexbytes);
+    small_serial = BN_hex2bn(&bignum, hexstr);
 
     Py_DECREF(hex);
     hex = NULL;
diff --git a/OpenSSL/util.c b/OpenSSL/util.c
index 661bb1d..3859cb8 100644
--- a/OpenSSL/util.c
+++ b/OpenSSL/util.c
@@ -60,6 +60,7 @@
     Py_DECREF(list);
 }
 
+#if (PY_VERSION_HEX < 0x02600000)
 PyObject* PyOpenSSL_LongToHex(PyObject *o) {
     PyObject *hex = NULL;
     PyObject *format = NULL;
@@ -77,14 +78,6 @@
         goto err;
     }
 
-#ifdef PY3
-    {
-        PyObject *hexbytes = PyUnicode_AsASCIIString(hex);
-        Py_DECREF(hex);
-        hex = hexbytes;
-    }
-#endif
-
     return hex;
 
   err:
@@ -99,3 +92,4 @@
     }
     return NULL;
 }
+#endif
diff --git a/OpenSSL/util.h b/OpenSSL/util.h
index f9e3a77..bfbbb6c 100644
--- a/OpenSSL/util.h
+++ b/OpenSSL/util.h
@@ -131,7 +131,7 @@
 #define PY_SSIZE_T_MIN INT_MIN
 #endif
 
-#if !defined(PyNumber_ToBase)
+#if (PY_VERSION_HEX < 0x02600000)
 extern PyObject* PyOpenSSL_LongToHex(PyObject *o);
 #else
 #define PyOpenSSL_LongToHex(o) PyNumber_ToBase(o, 16)