Fixed issue #4 (fail to clean up on exceptions)