Make sure we only add the last TxOut of created transactions as an unspent output when that is a change output

It might be easier to review each commit individually, as the first two ones
are just refactorings to make the actual fix simpler.
I guess addChange is always called 'last'. Meaning that other parts of the algorithm that doesn't know about the change output (for instance rollback) doesn't have to worry about the last TxOut being a change output. Maybe it would be worth noting something like that?