Slight rearrangement of key derivation