Implemented message sorting