Moved AutoCloseable bits into Close helper.