refactor client protocol
loop and fix