There is still the mystery of what global message type #22 is, but other than that concern, this code seems to work pretty well now.