Added multithreading to improve performance