added received messages,sent messages, improved code.