two unrelated bug fixes. I have not yet made a pull request for the msghash one
(waiting to see if I can find more bugs before doing that)