Fix thread access bug