extracted serialization logic into several classes