fixed some thread issues