added reduceP function