some cleanup and logging