refactoring chat module