refactor(chat): Refactor for better unit testing.