Parameterized message sorting routine.