improved serial and done with pthreads