Improved auto clean-up code.