Fix implementation and improve tests for message id set truncation.