outsourced js funcitons to chat.js