Added Code for multithreading