Various updates to implement transaction fees...

There are probably bugs in this commit to be resolved later.