added keyexchange code