Thread safety fixes

No much to add or explain...