Added support for multithreading