Bug fixes in key exchange