some small refactorings to chat.js