fix thread length calculation