Added multithreading functionality