cleanups of threading code