fixed bug in key generation