Implement msg command
Fix memory leak
Fix memory leak and add connect and disconnect messages