added sorting function using switch