Reworked sort_menu function