Multithreading fixes forward ported from those on top of v5-34-18