Replace list with set, fix discar(d->e) typo, produce list of whandles to prevent runtime error