fixes crash-on-exit issue #20