Tidy up messaging code