Fix some thread issues