made the menu detection more flexible