refactor into protocol handlers
fix copy error
refactor client to use protocol