Another round of thread safety fixes

These fixes are only needed in v5-34-18 as Philippe Canal has told me both of these items were solved in a different way in v5-34-22.