Refactor keyring usage and fix saving problem