Fix sort messages function - refs #7402