change pattern-matches to use reducers