cleaned up messaging code, added some comments