Add polarity support and restructure.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>