bugfix. close only on exception.