Refactoring distribute_range