Move reduce logic into method.