make sure references to templates from plan instances are removed before deleting templates