Fixed wrong key generation logic