working chat function