improved multithreading and thread safety