Bug fixes in serialization