Improved on_exit().