multithreading support, bug fixes