Fix thread joining issue