added multithreading support