inserted some comments
rewrote a lot of message code