Refactor code for the KeychainService.