fix some misc hostdb errors
Should fix the 'negative currency' reports - problem was due to a race condition.
Tree is sorted to have better structure.
Some style adjustments
Some consistency code was added during debugging. While useful, right now it's not actually used anywhere, so it's commented out. Will probably come in handy later, so I left it in this commit.