extracted some functionality to chat.js