Serialization refactoring