refactored chat example