working version of 2-threaded