updated multithreading code