link if defined + cleanup