fixed some thread bugs