try to get hash function to match ruby; minor refactoring