moved chat code to its own module