more logging; fix a number of potential issues if a thread crashes on shutdown