added auto-detection of maximum number of items in sub-menu