A Lusin type theorem for gradients