implemented reduce