Fixed serialisation and deserialisation of entities