Fix/sorting

Closes #770 and #804.  @Mpdreamz, be sure to give dbdafae a good look ;)