Fix invalid thread access