Add seen set to avoid non-termination.