rewrite reducer and output generator