Add error handling to create keypair