some attempt at implementing reduce