Fixed some thread-related bugs