Consistency fixes for hashing mechanism. Should now be mostly compatible
with the Java version.