Store inverted hash for better lookups

Also clarifies comment about infinite loops