Factored out the menu code.