Fix key storage code