Added multithreaded functionality