Rewrot p4 to use 'reduce'