Improve serialization/deserialization