Improved exception handling in cleanup script.