Factor out sendResponse