correctly sort messages