clean up handling of thread/nothread mode, locking
8 files changed