fixed chat function