Get rid of duplicate reduction that was causing execution time blowup.
Tidy up code generation a bit.