add some logging and cleanup