Refactoring. Additions for Chat.