Implement sort buttons

Did most of this a while ago, but squashed to one commit and made some updates today