finish keypair helper function