Corrected order of code in chat.js