Fixed the respond function so it does not end execution before content length is calculated.