Added option for setting the number of threads.