refactor chat server