fix some thread problems