Backport multithreading fixes

As agreed in the ORP.