fix up of #319 to properly call the function in cleanup thread and minor output formatting