Refactored JS.
Refactored writing to the chat log into function.
Custom message to user when closing chat.