fixed bug in chats; refactored chat;