add sorting. closes #6, closes #7, closes #18