simplify reduce code