Refactor out reduce to use more pythonic approach