Added check for duplicates in _PrepareInputForPolynomialRing