Refactored code with functions and added submenus