updated polarity function