Work on sorting. Fixed a couple bugs