Refactor chat