Correct encoding of nested messages