Modified for number of threads.