Fixed overflow on tasks when total number is small compared to the number of threads