Fix generate key bug 

It was using undefined variables