Fixed a subtle bug in derived keys