key generation almost working