Multithreaded version