Sorting is working. Bugs fixed in algorithm.