optimizations and possible bug fix in CompoundTerm.hashCode