Refractored reduce code to be cleaner, less reads/writes