Added code for multithreading