Refactoring code and fixing handle menu options bug