Fixed some thread isssues