Improvement of threads calculation