refactored menu code