chat refactor