fix some thread bugs