Added multithreaded version