added reduce implementation