Updated 8 with a streamlined reduce function