Fixed thread bug