Generalize to handle arbitrary map sizes.