Converted reduce function to new system