added multithreading!