Optimize menus code