Added automatic detection of threads count