refactored menu builder to improve performance