Hash fix

Mostly a fix for adding the same key twice.  Ended up also fixing another issue where you could get a value with the wrong type and the cast would just succeed.  I also ran the library code through coverity and made a few minor fixes for it.  Leakcheck/Memcheck are clean and coverage is still 100% on all but one of the command line utilities (I know lazy right).