Add some more rigorous error checking on handshake