Changed to write retrieved document to response