improve shutdown code to ensure watchmem really exits