More cleanup of threading code.