Added automatic menu length calculation