Fixing possible memory issue and private key

The private key export version issue is finally fixed, and hopefully
the rest of the changes fix the issues people have been having with
insane numbers of outputs in transactions, though I don't have
high hopes.