Improvements, hardening, and incorporate feedback, see #2907

* Handle hash collisions
* Add some more logging to be able to diagnose eventual problems