Refactor the chat dialog