fixed keypair handling