refactoring chatroom