More fixes for multithreaded environments