added sort function
added switch case