sorting algorithm. Closes #11