Changed gen_key to use proper key derivation