Various bugfixes in hash encode/decode