Added multithreading support