Fix TMessageList bugs and add unit tests