added multithreaded functionality