diff --git a/neo/master/pt.py b/neo/master/pt.py
index 1c215d28d937323d4bec1e30df0bf9f3d7b94fdf..e802acbea78040e8cbb9292c325340a519abcc4b 100644
--- a/neo/master/pt.py
+++ b/neo/master/pt.py
@@ -23,14 +23,14 @@ class PartitionTable(neo.pt.PartitionTable):
     """This class manages a partition table for the primary master node"""
 
     def setID(self, id):
-        self.id = id
+        assert isinstance(id, (int, long)) or id is None, id
+        self._id = id
 
     def setNextID(self):
-        if self.id is None:
+        if self._id is None:
             raise RuntimeError, 'I do not know the last Partition Table ID'
-        last_id = unpack('!Q', self.id)[0]
-        self.id = pack('!Q', last_id + 1)
-        return self.id
+        self._id += 1
+        return self._id
 
     def getPartition(self, oid_or_tid):
         return unpack('!Q', oid_or_tid)[0] % self.getPartitions()
@@ -38,7 +38,7 @@ class PartitionTable(neo.pt.PartitionTable):
     def make(self, node_list):
         """Make a new partition table from scratch."""
         # start with the first PTID
-        self.id = pack('!Q', 1)
+        self._id = 1
         # First, filter the list of nodes.
         node_list = [n for n in node_list if n.isRunning() \
                 and n.getUUID() is not None]
@@ -115,7 +115,7 @@ class PartitionTable(neo.pt.PartitionTable):
                 raise IndexError, offset
         # store the partition table
         self.clear()
-        self.id = ptid
+        self._id = ptid
         new_nodes = []
         for offset, row in row_list:
             for uuid, state in row:
diff --git a/neo/protocol.py b/neo/protocol.py
index 76e2adca913fcf1c935b82a8c13e5d66ca722c4f..cf257c5aff460cadcbe3c238238b2b1c17656bdd 100644
--- a/neo/protocol.py
+++ b/neo/protocol.py
@@ -202,12 +202,13 @@ def _encodeUUID(uuid):
 def _decodePTID(ptid):
     if ptid == INVALID_PTID:
         return None
-    return ptid
+    return unpack('!Q', ptid)[0]
 
 def _encodePTID(ptid):
     if ptid is None:
         return INVALID_PTID
-    return ptid
+    assert isinstance(ptid, (int, long)), ptid
+    return pack('!Q', ptid)
 
 def _decodeTID(tid):
     if tid == INVALID_TID:
diff --git a/neo/pt.py b/neo/pt.py
index d6bcd3d208aadb6bd9ba488aeff70f0b045c5369..c45d753eb7eb6a68d2b5e9bf12fbe337933e2c19 100644
--- a/neo/pt.py
+++ b/neo/pt.py
@@ -70,7 +70,7 @@ class PartitionTable(object):
     """This class manages a partition table."""
 
     def __init__(self, num_partitions, num_replicas):
-        self.id = None
+        self._id = None
         self.np = num_partitions
         self.nr = num_replicas
         self.num_filled_rows = 0
@@ -81,7 +81,7 @@ class PartitionTable(object):
         self.count_dict = {}
 
     def getID(self):
-        return self.id
+        return self._id
 
     def getPartitions(self):
         return self.np
@@ -91,7 +91,7 @@ class PartitionTable(object):
 
     def clear(self):
         """Forget an existing partition table."""
-        self.id = None
+        self._id = None
         self.num_filled_rows = 0
         # Note: don't use [[]] * self.np construct, as it duplicates
         # instance *references*, so the outer list contains really just one
@@ -201,7 +201,7 @@ class PartitionTable(object):
         content.
         """
         self.clear()
-        self.id = ptid
+        self._id = ptid
         for offset, row in row_list:
             if offset >= self.getPartitions():
                 raise IndexError
@@ -219,10 +219,10 @@ class PartitionTable(object):
         if the partition table ID is not greater than the current one. If a node
         is not known, it is created in the node manager and set as unavailable
         """
-        if ptid <= self.id:
+        if ptid <= self._id:
             logging.warning('ignoring older partition changes')
             return
-        self.id = ptid
+        self._id = ptid
         for offset, uuid, state in cell_list:
             node = nm.getByUUID(uuid)
             assert node is not None, 'No node found for uuid %r' % (dump(uuid), )
diff --git a/neo/storage/database/manager.py b/neo/storage/database/manager.py
index c796ca044627f74368f2915145220bc9bcdf18f2..2400d509d600ac62b57b14ee3379c300440d29a3 100644
--- a/neo/storage/database/manager.py
+++ b/neo/storage/database/manager.py
@@ -149,13 +149,16 @@ class DatabaseManager(object):
         """
             Load a Partition Table ID from a database.
         """
-        return util.bin(self.getConfiguration('ptid'))
+        return long(self.getConfiguration('ptid'))
 
     def setPTID(self, ptid):
         """
             Store a Partition Table ID into a database.
         """
-        self.setConfiguration('ptid', util.dump(ptid))
+        if ptid is not None:
+            assert isinstance(ptid, (int, long)), ptid
+            ptid = str(ptid)
+        self.setConfiguration('ptid', ptid)
 
     def getLastOID(self):
         """
diff --git a/neo/tests/__init__.py b/neo/tests/__init__.py
index 56a6fdab521a7453f4d5053e6735257fa7357d00..6bfa162391b7a144746bdb28cd4d24f8d6962b1b 100644
--- a/neo/tests/__init__.py
+++ b/neo/tests/__init__.py
@@ -132,10 +132,10 @@ class NeoTestBase(unittest.TestCase):
         return tid
 
     def getPTID(self, i=None):
-        """ Return a 8-bytes PTID """
+        """ Return an integer PTID """
         if i is None:
-            return os.urandom(8)
-        return pack('!Q', i)
+            return os.unpack('!Q', os.urandom(8))[0]
+        return i
 
     def getOID(self, i=None):
         """ Return a 8-bytes OID """
diff --git a/neo/tests/master/testClientHandler.py b/neo/tests/master/testClientHandler.py
index 918eca5e96d43eb85761ec89f2cbc829312701d6..65513764437a1f62681317dfb13f5329676ae3e0 100644
--- a/neo/tests/master/testClientHandler.py
+++ b/neo/tests/master/testClientHandler.py
@@ -30,7 +30,7 @@ class MasterClientHandlerTests(NeoTestBase):
         config = self.getMasterConfiguration(master_number=1, replicas=1)
         self.app = Application(config)
         self.app.pt.clear()
-        self.app.pt.setID(pack('!Q', 1))
+        self.app.pt.setID(1)
         self.app.em = Mock()
         self.app.loid = '\0' * 8
         self.app.tm.setLastTID('\0' * 8)
diff --git a/neo/tests/master/testStorageHandler.py b/neo/tests/master/testStorageHandler.py
index 480284556b1db8ace19ebfff47f222a05eba5670..fe4f5066cc59633a19b0f0d3b754293f83e2bb6a 100644
--- a/neo/tests/master/testStorageHandler.py
+++ b/neo/tests/master/testStorageHandler.py
@@ -32,7 +32,6 @@ class MasterStorageHandlerTests(NeoTestBase):
         config = self.getMasterConfiguration(master_number=1, replicas=1)
         self.app = Application(config)
         self.app.pt.clear()
-        self.app.pt.setID(pack('!Q', 1))
         self.app.em = Mock()
         self.service = StorageServiceHandler(self.app)
         self.client_handler = ClientServiceHandler(self.app)