Thread bug fix