Refactor menu code