Cse rewrite

A rewrite of common-subexpression-elimination. The old version was pretty flaky.
style nit: commented-out-code should probably be removed, or a comment added about why it's here but commented out.