Fix some fundamental flaws in how the keychain is handled.