Add a MenuItem class and factor out functions from directive