Fix thread problem