changed sort function to include a switch statement