added input polarity function