fixed wrong order in generate_keypair()