move all script code into chat.js file