Added multithreaded support