main chat functionality