Fix TNM ConcurrentModificationException which could occur when shutting down