Refactor menu system code