changed free(response) to only free if response is allocated on heap