multithreaded implementation