Refactor message builders, rewrite some tests.