move chat function to its own namespace