Port the message/envelope refactoring to Ruby.