Fixes for hash database code

These are the latest fixes from Sam Kenyon, merged into my hashdb_comments branch.