cleanup and logging