added sortList function to clear up sorting code