failed to implement the sorting message function

I thoroughly don't understand my own messaging code and it's like 15 lines
long. Atta boy.