moved serialization logic to serializer class