replace Counter with defaultdict
use defaultdict(set) for phrase_to_internals. update docstring
strip trailing whitespace