move response serialization into helper method