added a lot of code for messaging functionality