chat: some refactoring