refactor chat client