dynamic menus and submenu algorithm