fix various bugs in the DEBUG_THREADS code including: