Fixes for multithreading