Refactor menu code, and move it to menu.c