Refactor serialization.