Fix to prevent sending response after headers sent.