some cleanup and additional logging functionality