minor cleanup and recoded a chat class with it's function

messages are now correctly encoded