refactor serialization