Refactor chat service