Began sorting algorithm