refactoring download keypair function for mac