finished multithreading implementation