refactor chat callbacks