Clean up and simplify handshaking
Fix race condition in sendbuffer