Refactored and simplified multipart serializer.