Here I'd suggest using the same logic as is now in recv_keys()