Move the logic for constructing the response into the response