Multithreading optimal version