Solving the multithreading issue