Refactored allocateContainers()