Added key derivation logic