Refactoring keygen so it can return the keypair if wanted