Added writeResponseToClient to handle all response writing to the client