Refactoring plus fixed detection of number of chunks and reduce workers