Added dynamic check for max thread count.