Created the code for multithreaded