Fix thread bug