Refactor creation of the response object