Various bug fixes and/or better code
Merge pull request #2015 from fstagni/fixAccounting

[v6r12] Various bug fixes and/or better code in the accounting