Tweaking the AutoCloseable logic to avoid ConcurrentMod