Refactor key loading logic into its own method for clarity and better error reporting.