issue #79 - do cleanup only on internal error