some code streamlining, add hook interface, outsource disambiguate

disambiguate is outsourced to a hook function, to keep it all in one
place.