I took this from Escape functions