refactored serialization