improved xml cleanup error handling