exit bugfix and resource disposal