chat cod refactoring