Small improvements to the keychain function