Cleanup

Since the old cleanup branch is now un-merged, here are the same changes again, disentangled this time from the amounts branch.