Incorporated changes from the hashfun branch.