refactor client protocol