cleaning; fix bug with key generation