added support for selecting number of threads