TODO: cleanups for close and leave