added flag to specify number of threads to use