added functionality of adapting to the given map but respecting a preset max number of size